note 28579 added to tutorial.forms

From: Date: Fri, 17 Jan 2003 10:34:13 +0000
Subject: note 28579 added to tutorial.forms
Groups: php.notes 
Request: Send a blank email to php-notes+get-42262@lists.php.net to get a copy of this message
It is sometimes useful to have more than one SUBMIT button in a form so that PHP can detect which one has been clicked and take appropriate action. The value of the SUBMIT button does not come via $_POST or $_GET but it can be obtained using $_REQUEST. Example: this is file TESTFORM.HTM: --------------------------- <h1>Form to test button detection in PHP</h1> <form name="form1" id="form1" method="post" action="processtestform.php"> <input name="textfield" type="text" value="Enter text here" size="25" maxlength="25" /> <br /> <input name="submit1" type="submit" id="submit1" value="Submit (button 1)" /> <br /> <input name="submit2" type="submit" id="submit2" value="Submit (button 2)" /> </form> ----------------------------------------------------- This is file PROCESSTESTFORM.PHP: ----------------------------------- <h1>Results of processing TESTFORM.HTM input</h1> <?php echo "textfield contents: " . $_POST["textfield"]."<br>"; echo "button used: " ; echo @$_REQUEST["submit1"]; echo @$_REQUEST["submit2"]; ?> ----------------------------------------------------- -- http://www.php.net/manual/en/tutorial.forms.php http://master.php.net/manage/user-notes.php?action=edit+28579 http://master.php.net/manage/user-notes.php?action=delete+28579 http://master.php.net/manage/user-notes.php?action=reject+28579

« previous php.notes (#42262) next »