A form with two submit buttons with a different value
<form action="here.php" method="POST"> <input type="text" name="text"> <div id="one"> <input type="hidden" name="aaa" value="one"> <input type="submit" value="Send"> </div> <div id="two"> <input type="hidden" name="aaa" value="two"> <input type="submit" value="Send"> </div> </form> Now, if I click "Submit" an ONE div or a TWO div, I'm always at $ _ POST ['aaa'] = 'two';
Is it possible to make one form with two submissions with different values?
If I click on the div, send, I would like to show $ _ POST ['aaa'] = 'one' , and if I click on the div two submit, I would like to get $ _ POST ['aaa'] = 'two' .
How can i do this?
I can use PHP and jQuery for this.
EDIT: I do not want to create two forms - I do not want to show two times <input type="text" name="text">
EDIT: maybe I can send a button instead? but how?
It looks like what you really want to do is the value in each of the buttons, see this , for example:
<form action="demo_form.asp" method="get"> Choose your favorite subject: <button name="subject" type="submit" value="fav_HTML">HTML</button> <button name="subject" type="submit" value="fav_CSS">CSS</button> </form> You will need two different forms:
<div id="one"> <form ...> <input type="hidden" name="aaa" value="one"> <input type="submit" value="Send"> </form> </div> <div id="two"> <form ...> <input ...> <input ...> </form> </div> The standard practice is that when two fields have the same name , use only the LAST value found in the form and represent it.
PHP has a special notation ( name="aaa[]" ) to allow sending multiple values ββwith the same name, but that would not help you here, since it would pass ALL the aaa values, not just the one closest to the submit button.
HTML form:
<form ...> <input type="text" name="textfield"> <div id="one"> <input type="hidden" name="one_data" value="aaa" /> <input type="submit" name="submit_one" value="Submit" /> </div> <div id="two"> <input type="hidden" name="two_data" value="bbb" /> <input type="submit" name="submit_two" value="Submit" /> </div> </form> server side:
if (isset($_POST['submit_two'])) { $data = $_POST['two_data']; } else if (isset($_POST['submit_one'])) { $data = $_POST['one_data']; } else { die("Invalid submission"); } Try the following:
in html -
<input id="PreviousButton" value="Previous" type="submit" /> <input id="NextButton" value="Next" type="submit" /> <input id="Button" name="btnSubmit" type="hidden" /> in jOuery -
$("#PreviousButton").click(function () { $("#Button").val("Previous"); }); $("#NextButton").click(function () { $("#Button").val("Next"); }); then you can see in the form results what the "Button" contains.