-
$php_self
Hi, I learned at Kevin's tut to use $PHP_SELF in a form as "action" to be redirected to the same page.
For example like this :
PHP Code:
if $submit:
put the staff in the db
else :
<form action=$PHP_SELF>
show the form
</form>
endif:
Now I recognized that it also worked fine without the "$PHP_SELF", I just left the action field blank. Now my project is online and people report me that when they click submit nothing happens, they just see the blank form again. Can there be any correlation and if so why does it work on my computer ? ( one told me it worked one time out of 6 ) So what's going on here. Please help me, it's urgent.
-
Remeber it needs to be in <?php ?> tags - I personally recommend using basename($PHP_SELF) instead as it saves you getting nasty paths incorporating your PHP cgi on some installs of PHP:
<form action="<?php echo basename($PHP_SELF); ?>">
-
But I'm still not sure if this is the problem, and I can not test it as it works fine when I do it. Anyway why do you nead $PHP_SELF or basename($PHP_SELF) when it also works without.
By the way, I'm using FastTemplates, is it just fine to have the form in a template like this
<form action='{ACTION}'>
....
and than parse "basename($PHP_SELF)" to the template into {ACTION} ?
-
It should work just fin with fastTemplate if you do that. You should include an action for the form because although Internet Explorer defaults to usign the current page as the ACTION of the form other browsers may not do this.
-
Ok, just once again . As far as I know, for my PHP Skripts it doesn't matter:
- which Browser the user has
- if he is using a firewall etc.
- if he is using the Internet via an Intranet ( like in a company ) etc.
Is it correct? Because I still don't know why the skript didn't work in some cases but without any problems on my Computer ( and many others ).
-
Yeah thats correct but the way you are calling your scripts may vary..
lets say i use $PHP_SELF than if you look at the source it will say:
action="filename.php"
or even
action="directory/filename.php"
If you don't use $PHPSELF and just type nothing then in the source (browser source) it will say
action=""
While IE presumes that the action is directed to the file itself other browsers may not..
So the script is working fine but if you don't send the variables because the browsers thinks action = none or only refresh the page won't be loaded correctly..
So if you don't want to depend on browsers use an action.
Greets
Peanuts
-
Sorry, me again. They just told me which pages worked and which not. Now it's funny, but those pages without $PHP_SELF ( without any "action" in the form tag ) worked and those with a correct action did not work ( they just saw the blank form again )
That's strange, isn't it? Any idea.
-
One thing to keep in mind is that IE will default to the same page if the action is omitted. Netscape will die.