Nick Nick - 20 days ago 7
PHP Question

One form with two submit buttons and different actions for each button

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.

Answer

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" />