PHP_SELF
Posted: Mon Dec 06, 2010 10:01 pm
Just a general question regarding the use of the PHP_SELF variable in forms. According to most examples I have seen (ex: http://www.html-form-guide.com/php-form ... -self.html), if you use the php self variable in the action of a form, you need an if statement before the form. For example:
Why is it necessary to check if the form has already been submitted and why won't the form work without this check (if statement)?
Thanks
Code: Select all
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
echo "User Has submitted the form and entered this name : <b> $name </b>";
echo "<br>You can use the following form again to enter a new name.";
}
?>
<HTML>
<HEAD><title>Using PHP_SELF</title></HEAD>
<BODY>
<FORM method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="name"><br>
<input type="submit" name="submit" value="Submit Form"><br>
</FORM>
</BODY>
</HTML>Why is it necessary to check if the form has already been submitted and why won't the form work without this check (if statement)?
Thanks