I have 2 buttons in HTML form. And both of them should submit the form. I would need to capture which button has been clicked so i can use it to perform different actions based on which button was clicked.
I am able to submit the form with both the buttons but how would i capture which button was clicked in the php file .
<INPUT type="button" name="submit" class="button" class="element_2" value="firstbutton">
<INPUT type="button" name="submit1" class="button" class="element_2" value="second button.. ">
i am using post method in Jquery to submit the form. How can i check which HTML button was clicked in server side php script
You could use a hidden element here, something like this:
Your current
.submit()handler using.serialize()and$.post()should work, just update the hidden field when clicking either button, for example:Then in PHP just check that
$_POST["submittedBy"] == "submit"or"submit1"to see which caused it.The alternative is to have the
clickhandler POST and add in the value between.serializeArray()and when$.param()is called, like this: