HTML form with multiple "actions"

I set up a form in which I need two "actions" (two buttons):

1 - "Submit this form for approval"
2 - "Save this application for future use"

How to create an HTML form that supports several "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 parameters for presentation in one form.

I did some basic research, but could not find a definitive answer as to whether this is possible and / or any good resources for links to a workaround.

Thanks in advance.

+59
html submit forms
May 21 '13 at 1:27
source share
3 answers

As @AliK mentioned, this can be done easily by looking at the meaning of the submit buttons.

When you submit the form, undefined variables will evaluate to false. If you set both submit buttons to the same form, you can simply check which button was installed.

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




If you do not want to change your PHP setting, try the following: http://pastebin.com/j0GUF7MV
This is the JavaScript method that @AliK repeated.

on this topic:

  • 2 submit buttons for actions with a different URL
  • Submit the form to another page (which is different from the page used in ACTION)
+68
May 21 '13 at 2:12
source share

the best way (for me) to make it the following infrastructure:

 <form method="POST"> <input type="submit" formaction="default_url_when_press_enter" style="visibility: hidden; display: none;"> <!-- all your inputs --> <input><input><input> <!-- all your inputs --> <button formaction="action1">Action1</button> <button formaction="action2">Action2</button> <input type="submit" value="Default Action"> </form> 

with this structure you will send with direction input and infinite possibilities for the rest of the buttons.

+18
Oct 07 '16 at 7:38
source share

this is a really worked out form, because I make a table using the timeline, and inside the table there are two buttons in one form ... thanks, man, even this thread is old, it still helps me a lot!

 <th:block th:each="infos : ${infos}"> <tr> <form method="POST"> <td><input class="admin" type="text" name="firstName" id="firstName" th:value="${infos.firstName}"/></td> <td><input class="admin" type="text" name="lastName" id="lastName" th:value="${infos.lastName}"/></td> <td><input class="admin" type="email" name="email" id="email" th:value="${infos.email}"/></td> <td><input class="admin" type="text" name="passWord" id="passWord" th:value="${infos.passWord}"/></td> <td><input class="admin" type="date" name="birthDate" id="birthDate" th:value="${infos.birthDate}"/></td> <td> <select class="admin" name="gender" id="gender"> <option><label th:text="${infos.gender}"></label></option> <option value="Male">Male</option> <option value="Female">Female</option> </select> </td> <td><select class="admin" name="status" id="status"> <option><label th:text="${infos.status}"></label></option> <option value="Yes">Yes</option> <option value="No">No</option> </select> </td> <td><select class="admin" name="ustatus" id="ustatus"> <option><label th:text="${infos.ustatus}"></label></option> <option value="Yes">Yes</option> <option value="No">No</option> </select> </td> <td><select class="admin" name="type" id="type"> <option><label th:text="${infos.type}"></label></option> <option value="Yes">Yes</option> <option value="No">No</option> </select></td> <td><input class="register" id="mobileNumber" type="text" th:value="${infos.mobileNumber}" name="mobileNumber" onkeypress="return isNumberKey(event)" maxlength="11"/></td> <td><input class="table" type="submit" id="submit" name="submit" value="Upd" Style="color: white; background-color:navy; border-color: black;" th:formaction="@{/updates}"/></td> <td><input class="table" type="submit" id="submit" name="submit" value="Del" Style="color: white; background-color:navy; border-color: black;" th:formaction="@{/delete}"/></td> </form> </tr> </th:block> 
0
Feb 03 '19 at 7:36
source share



All Articles