PHP - Value of a Submit

1,751 views
Skip to first unread message

Warren Michelsen

unread,
Nov 20, 2009, 3:58:33 PM11/20/09
to Web Authoring List

If a form has multiple Submit buttons, how does one find, in php, the value of the submit that was used?

That is, I have one submit to 'Modify' and another to 'Delete" the submitted form data.
<input name="Delete" type="submit" value="Delete">
<input name="Submit" type="submit" value="Modify">


if($_POST['Submit'])

Seems only to provide confirmation that a form was submitted. How do I extract the value of the Submit button that was used?

How can I use php to tell me which of the above Submits was used?

bill

unread,
Nov 20, 2009, 6:00:25 PM11/20/09
to Web Authoring
$_POST will contain the key/values for each form elements that are
submitted and have values by element name. As such, using your
example, when the Delete submit button is clicked, $_POST["Delete"]
will be created with the value of "Delete" but there will not be a
$_POST["Submit"] created or have a value since it wasn't clicked.

Govinda

unread,
Nov 20, 2009, 6:07:08 PM11/20/09
to web-au...@googlegroups.com


get the *name* of the variable coming in... write conditionals based
on that.
I am not in PHP mode these days, so you'll have to check syntax/write
it yourself.. but something like (pseudo code) -

$deleteVar=$_POST['Delete'];
$sumitVar=$_POST['Submit'];

if ($deleteVar=="Delete") {
dosomething;
} elseif ($sumitVar =="Modify") {
dosomethingElse;
}

..just to give an idea of one myriad ways you can approach this.

------------
Govinda
govinda.w...@gmail.com

Reply all
Reply to author
Forward
0 new messages