Page 1 of 1
$PHP_SELF not working correctly...
Posted: Wed Dec 15, 2004 8:58 pm
by Hibba
Below I have a basic php file that displays a form if 'submit' is not set. I have the html file by itself and bring it in using file_get_contents, but the $PHP_SELF within that HTML file does not seem to work. Why?
Code: Select all
<?
extract($_Post);
if (!isset($submit)) { //if the form has NOT been submitted, show the following HTML
echo file_get_contents('donate_form.html');
} else { //if it HAS been submitted, give them text
//email variables and POST again
}
?>
//donate_form.html (below)
<html>
html...
<form id="FormName" action="<?=$PHP_SELF?>" method="POST" name="FormName">
html...
</form>
</html>
Posted: Wed Dec 15, 2004 9:01 pm
by timvw
Posted: Wed Dec 15, 2004 9:06 pm
by Hibba
Hmm, do you mean action="<?=$_SERVER['PHP_SELF']?> ??
Cause this does not seem to work either.
Posted: Wed Dec 15, 2004 9:12 pm
by rehfeld
sometimes peoples php installation doesnt define the php_self variable for some reason.
i have no clue why.
only thing i can think of is if track_vars is off
ive seen a few people mention this.
make sure short tags is turned on as well
try using <?php echo instead of <?=
Posted: Wed Dec 15, 2004 9:13 pm
by Hibba
This is just installed on my powerbook with the local Apache server...
Is there a way I can check this?
Posted: Wed Dec 15, 2004 9:14 pm
by rehfeld
yes do
phpinfo();
Posted: Wed Dec 15, 2004 9:20 pm
by Hibba
It says this:
_SERVER["PHP_SELF"]
/simple forms/phpinfo.php (which was the file that I used to access it)
This worked in another php file I used. It seems like having it with file_get_contents messes it up or something...
Posted: Wed Dec 15, 2004 9:40 pm
by rehfeld
file_get_contents reads the file into a string, it does not parse it
use include()
Posted: Wed Dec 15, 2004 9:43 pm
by Hibba
But if I use include(), then I will need to escape all quotes. Correct? Also wouldn't I need to assign the HTML to a variable and then return(variable)??
thanks so much.
Posted: Wed Dec 15, 2004 9:52 pm
by andre_c
no, the webserver will only parse as php blocks between <? and ?> or <?php and ?> if short open tags is off.
so you don't need to escape any quotes that are not inside those tags
Posted: Wed Dec 15, 2004 9:57 pm
by Hibba
Right, but the include is between PHP blocks in the main file. When I submit now, it returns me back to the page, also has a "1" at the bottom of the form.
Posted: Wed Dec 15, 2004 11:29 pm
by ol4pr0
Code: Select all
<?
#good bye extract
if (!isset($_POST['submit'])) {
include('donate_form.html');
} else { //if it HAS been submitted, give them text
//email variables and POST again
}
?>
//donate_form.html (below)
<html>
<form id="FormName" action="<?echo $_SERVER['PHP_SELF'];?>" method="POST" name="FormName">
</form>
</html>
Have a nice Day
