note 69756 deleted from tutorial.forms by philip
| From: | philip@php.net | Date: | Wed, 21 Feb 2007 16:26:10 +0000 |
| Subject: | note 69756 deleted from tutorial.forms by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-123669@lists.php.net to get a copy of this message | ||
Note Submitter: evlooij at xs4all dot nl
----
I agree that the manual is not very clear on how one should structure the files, but it is not true
that the action attribute of a form always points to a different file: it can also point to the same
file. Say you have a file called myForm.php with the following code:
<html>
<body>
<form method="post" action="action.php" target="_self">
<button type="submit" name="actionToTake" value="Hello
there!">Say hello</button>
</form>
</body>
</html>
Then you would indeed need to create a file named action.php and have it do something like <?php
echo
"<html><body>".$_POST['actionToTake']."</body></html>";
?>
But you'll often find that it is handier to let myForm.php handle your user's input, so
then you would set the action to the current page, and for that PHP has a nice variable $PHP_SELF to
help you:
<html>
<body>
<?php echo "actionToTake=".$_POST['actionToTake']."\n" ?>
<form method="post" action="<?php echo $PHP_SELF ?>"
target="_self">
<button type="submit" name="actionToTake" value="Hello
there!">Say hello</button>
</form>
</body>
</html>
Hope this helps you get started.