I'm setting up a form wherein I need two "actions" (two buttons):
1 - "Submit this form for approval"
2 - "Save this application for later"
How do I create an HTML form that supports multiple "actions"?
EG:
<form class="form-horizontal" action="submit_for_approval.php">
<form class="form-horizontal" action="save_for_later.php">
I need to combine these two options-for-submitting into one form.
I did some basic research but couldn't find a definitive answer as to whether or not this is possible, and/or any good resources to links for a workaround.
Thanks in advance.
Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.
No, a form has only one action.
yes, multiple submit buttons can include in the html form. One simple example is given below.
Yes, the form is required to have an action attribute in HTML4. If it's not set, the browser will likely use the same method as providing an empty string to it. You really should set action="" which is perfectly valid HTML4, follows standards, and achieves the same exact result.
As @AliK mentioned, this can be done easily by looking at the value of the submit buttons.
When you submit a form, unset variables will evaluate false. If you set both submit buttons to be part of the same form, you can just check and see which button has been set.
HTML:
<form action="handle_user.php" method="POST" /> <input type="submit" value="Save" name="save" /> <input type="submit" value="Submit for Approval" name="approve" /> </form>
PHP
if($_POST["save"]) { //User hit the save button, handle accordingly } //You can do an else, but I prefer a separate statement if($_POST["approve"]) { //User hit the Submit for Approval button, handle accordingly }
EDIT
Related:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With