Jump to content

Archived

This topic is now archived and is closed to further replies.

Brendan

php_self problem

Recommended Posts

[b]SOLVED[/b]

OK, i have a script with a form in it, form.php, included in a file with the layout and everything, index.php.

Now say i want to put action="<?php print $_SERVER['PHP_SELF'] ?>" in the form, so that when i click submit the form submits the information to its self.

The problem is that the form submits to the file its included in, index.php, instead of to its self, form.php. So when i want it to be action="form.php" it ends up being action="index.php" instead.

Share this post


Link to post
Share on other sites
it's generally best when doing forms, unless there really small, actually it's best always to use an external php file to send the information to, you can do it, and there is an explanation of how at
[a href=\"http://www.hudzilla.org/phpbook/\" target=\"_blank\"]http://www.hudzilla.org/phpbook/[/a]
under the chapter html forms, just skim over that and you can find all the answers you need, but generally you want the file to send to an external file.

Share this post


Link to post
Share on other sites
@Brendan

php_self points to the generated file (includes included) so that in your case the form points correctly to index.php not to the originally included form.php code. If you think of include as equivalent to the server doing a copy/paste of the include into the file called you'll see why index.php is the real 'self'. If you want/need form.php as a standalone script that can submit on itself, you'll need form.php as a separate file which is not included but accessed by link.

Share this post


Link to post
Share on other sites
[!--quoteo(post=367410:date=Apr 21 2006, 11:02 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Apr 21 2006, 11:02 PM) [snapback]367410[/snapback][/div][div class=\'quotemain\'][!--quotec--]
@Brendan

php_self points to the generated file (includes included) so that in your case the form points correctly to index.php not to the originally included form.php code. If you think of include as equivalent to the server doing a copy/paste of the include into the file called you'll see why index.php is the real 'self'. If you want/need form.php as a standalone script that can submit on itself, you'll need form.php as a separate file which is not included but accessed by link.
[/quote]

So then i'm assuming there isn't a function that will return the script filename where the function is used? If not, then how would i go about including it as a seperate link, while still being imbedded in the current page?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.