note 69756 added to tutorial.forms

From: Date: Tue, 19 Sep 2006 16:36:35 +0000
Subject: note 69756 added to tutorial.forms
Groups: php.notes 
Request: Send a blank email to php-notes+get-117328@lists.php.net to get a copy of this message
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. ---- Server IP: 83.137.20.120 Probable Submitter: 80.126.196.150 ---- Manual Page -- http://www.php.net/manual/en/tutorial.forms.php Edit -- https://master.php.net/note/edit/69756 Del: integrated -- https://master.php.net/note/delete/69756/integrated Del: useless -- https://master.php.net/note/delete/69756/useless Del: bad code -- https://master.php.net/note/delete/69756/bad+code Del: spam -- https://master.php.net/note/delete/69756/spam Del: non-english -- https://master.php.net/note/delete/69756/non-english Del: in docs -- https://master.php.net/note/delete/69756/in+docs Del: other reasons-- https://master.php.net/note/delete/69756 Reject -- https://master.php.net/note/reject/69756 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117328) next »