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

后端 未结 4 1887
野趣味
野趣味 2020-12-03 00:57

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 ON

相关标签:
4条回答
  • 2020-12-03 01:42

    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" />
    
    0 讨论(0)
  • 2020-12-03 01:55

    Finally, I got my answer after spending more than an hour. I tried a various method like switch case, jquery, and JavaScript. But I only used HTML5 formaction tag and now my form two submit button working at two location.

    Code :

       <input type="submit" class="btn btn-success" value="Pay Now" name="submit"  style="width: 100%; letter-spacing: 1px; color: #fff; border: none;padding:  10px;" formaction="example.php">
    
       <button type="submit" class="btn btn-success" name="submit" style="width: 100%; letter-spacing: 1px; color: #fff; border: none;padding: 10px; margin-top: 15px;" formaction="mail.php"> Button</buttton>

    0 讨论(0)
  • 2020-12-03 01:58

    I have the same issue. but the thing is the first button function is in JS while the other is using PHP.

    $('#add-bookingid').submit(function(e){
    e.preventDefault();
    calculateDistance();
    });
    

    You see $('#add-bookingid').submit so both buttons have same button type as submit.

    Main Purpose

    Button# 1

    Button# 2

    0 讨论(0)
  • 2020-12-03 01:59

    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

    0 讨论(0)
提交回复
热议问题