I have a website started where I want to have 2 separate submit buttons, one of which will take data entered and do some calculations to it to display on the same screen. I've got this successfully working with:
<form id="form1" name="form1" method="post" onsubmit="" onreset="" action="programname.php"> <input type="submit" name="calc" value="Find Angle">
and then I use:
if (!isset($_POST['submit'])){ Do actions, display calculations}
Now I want a second submit button that still grabs the data they entered but then goes to a different address. Is there an elegant way to do this?
Put a hidden field. And when one of the buttons are clicked before submitting, populate the value of hidden field with like say 1 when first button clicked and 2 if second one is clicked. and in submit page check for the value of this hidden field to determine which one is clicked. Show activity on this post.
Processing form data in PHP is significantly simpler than most other Web programming languages. This simplicity and ease of use makes it possible to do some fairly complex things with forms, including handling multiple submit buttons in the same form.
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.
yes, multiple submit buttons can include in the html form. One simple example is given below.
You could add an onclick
method to the new submit button that will change the action of the form and then submit it.
<script type="text/javascript"> function submitForm(action) { var form = document.getElementById('form1'); form.action = action; form.submit(); } </script> ... <form id="form1"> <!-- ... --> <input type="button" onclick="submitForm('page1.php')" value="submit 1" /> <input type="button" onclick="submitForm('page2.php')" value="submit 2" /> </form>
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