Jump to content


Photo

php_self problem


  • Please log in to reply
3 replies to this topic

#1 Brendan

Brendan
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 21 April 2006 - 10:56 PM

SOLVED

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.

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 22 April 2006 - 01:29 AM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 April 2006 - 03:02 AM

@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.
Legend has it that reading the manual never killed anyone.
My site

#4 Brendan

Brendan
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 22 April 2006 - 04:23 PM

[!--quoteo(post=367410:date=Apr 21 2006, 11:02 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Apr 21 2006, 11:02 PM) View Post[/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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users