I am working on a website where I have 2 forms on 1 page. I use 1 PHP script to check the forms. But if I submit my second form on the page, my website submits the first form. How can I check which form is submitted?
<!--// Form 1-->
<form method="post">
<input type="text" name="test">
<input type="submit" name="submit">
<input type="hidden" name="page_form" value="1">
</form>
<!--// Form 2-->
<form method="post">
<input type="text" name="test">
<input type="submit" name="submit">
<input type="hidden" name="page_form" value="2">
</form>
PHP:
if(isset($_POST['submit'])) {
$forms = array(1, 2);
foreach($forms as $form) {
if($_POST['page_form'] == $form) {
// All my form validations which are for every form the same.
}
}
}
Use isset() method in PHP to test the form is submitted successfully or not. In the code, use isset() function to check $_POST['submit'] method. Remember in place of submit define the name of submit button. After clicking on submit button this action will work as POST method.
$("#something-%"). submit(function(e) { e. preventDefault(); $("#some-span"). html(data); });
The Correct Answer is " Request.
PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables. The example below shows a form with an input field and a submit button.
What to do it this way:
<!--// Form 1-->
<form method="post">
<input type="text" name="test">
<input type="submit" name="form1" value="Submit form">
</form>
<!--// Form 2-->
<form method="post">
<input type="text" name="test">
<input type="submit" name="form2" value="Submit form">
</form>
And check which form was submitted:
if(isset($_POST["form1"]))
echo "Form 1 have been submitted";
else if(isset($_POST["form2"]))
echo "Form 2 have been submitted";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With