A problem getting a form action attribute to find the target

I’m struggling with some behaviour of the form ‘action’ attribute which I cannot understand…
I’m trying to get a form to respond to “action=‘members/login_handler.php’”, but when I submit I get a (PHP) error message: “The requested URL /login_handler.php was not found on this server”. The path ‘members/’ seems to have been ignored. There is definitely a file of that name in that folder.

If I put “action=‘anotherfolder/login_handler.php’” (where there is NOT a file of that name in the folder) the error reads: ‘The requested URL anotherfolder/login_handler.php was not found on this server’. In this instance the path ‘anotherfolder/’ has not been ignored.

If I copy ‘login_handler.php’ into ‘anotherfolder’ I get the original error message (where the path seems to be ignored).

If I put a copy of ‘login_handler.php’ in the root folder it is found, but I’d much prefer not to do this. I’ve probably made a stupid error, but can anyone help me to work out what it is, please?

I’ve tried several variants (e.g. “action=‘/members/login_handler.php’” to no avail.

The form is in a file ‘members/login_page.php’'. The folder ‘members’ is in the web site root. At present this is all on my local machine, so I can’t yet post a link,

What I would do is put the following script snippet at the top of the page you want to go to (the page the action lands on), it should give you the directory and the file name:

/* Get the current page */
echo "<pre>" . print_r($phpSelf, 1) . "</pre>\n";

Thank you for that suggestion. I had already done something similar - I’d put the name and path for each version to be echoed at the top of the file. The trouble is the ONLY version I seem to get is the one in the root. If that’s not there I get an error message.

I suspect the problem may arise because I’ve got a ‘chain’ of includes:
/index.php → includes pageTemplate.php → requires login_page.php which actually displays the login page. When the login form is submitted it calls ‘login_handler.php’ which is another control script which is not itself displayed. I’d have thought that by putting the path in the action attribute of the form it would follow the path and not simply go back to the root.

Tracking the process more thoroughly I find that the file in the action attribute IS being found (i.e. “action=‘members/login_handler.php’” DOES work as expected), but someting in my script must then be calling the login_handler.php in the root.

This is something I’ll need to sort out for myself. As so often, putting the issue on the Sitepoint Forum has forced me to clear my mind of preconceptions and think it through from square one.

1 Like

I was going to suggest if you’re sure if you didn’t have any capital letters or anything like that. Except Microsoft IIS, web servers tend to be picky with letter case.

But it looks like you have it under control

Thanks. Yes, I’d gone through that possibility very carefully !

I’ve found it now. The routine that validated the login SHOULD have returned to ‘members/login_handler.php’ but returned to the root version instead. Hence the error message if ‘/login_handler.php’ didn’t exist.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.