One Form, Multiple Actions
November 16th, 2005
Not everyone is aware of this fact, so I thought I'd share it. You can have a single form, with multiple submit buttons, and then determine which button was clicked as to what action to take. Take the following code:
<form action="test.php" method="post"> <input type="submit" name="edit" value="edit" /><br />
<input type="submit" name="delete" value="delete" /><br />
</form>
If your user clicks on the "edit" button, then $_POST["edit"] will be available, and the same if they click on the "delete" button. You can test for these buttons within your PHP code, and then perform the related actions:
You can of course have as many buttons as you wish - thus having as many actions as necessary.
Add to del.icio.us
Digg this
Technorati
Related Posts:
- More multiple submit buttons
- More on submitting forms
- Variable Casting
- File Uploads
- Email Header Injection in PHP
Entry Filed under: PHP
3 Comments Add your own
1. Chris H | November 19th, 2005 at 1:02 am
Cool!
Never really considered that. Consider it cut n pasted.
2. misiek | April 27th, 2007 at 3:08 pm
How to do in ajax.
I need to sibmit ajax form, this way it return whole params, for all buttons
3. Ed Costa | April 29th, 2008 at 9:20 am
Just what I was looking for… thanks to you, the script fals into place! Thanks.
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed