I have spent several hours trying to find a solution to my issue, but just can't seem to find the proper solution. Thanks in advance for your assistance!
I have ONE html form with:
<form id="columnarForm" action="formindb_hoh_1.php" enctype="multipart/form-data" method="post" />
I would like to have TWO submit buttons:
<input type="image" name="camper" value="camper" src="../images/apps/camperBtn.png" class="submit_button" /> <input type="image" name="medical" value="medical" src="../images/apps/medicalBtn.png"class="submit_button" />
I would like the first submit button to have the action of formindb_hoh_1.php when clicked and the second submit button to have the action of formindb_hoh_2.php, but am unsure how to make one button have one action and have the other button has a different action.
yes, multiple submit buttons can include in the html form. One simple example is given below.
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.
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.
Refer this :
Multiple submit buttons php different actions
Put this script in your page :
<script> function submitForm(action) { document.getElementById('columnarForm').action = action; document.getElementById('columnarForm').submit(); } </script>
Modify your input code :
<input type="image" name="camper" onclick="submitForm('formindb_hoh_1.php')" value="camper" src="../images/apps/camperBtn.png" class="submit_button" /> <input type="image" name="medical" onclick="submitForm('formindb_hoh_2.php')" value="medical" src="../images/apps/medicalBtn.png"class="submit_button" />
No JS, use HTML5.
Change the submit buttons to use new HMTL5 button attribute formaction:
<button type="submit" name="camper" formaction="formindb_hoh_1.php">Camper</button> <button type="submit" name="camper" formaction="formindb_hoh_2.php">Medical</button>
Reference: http://devdocs.io/html/element/button
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