PHP

Checking Whether a Form Has Been Submitted

if (isset($_POST['Submit'])) { ...
} else { ...
}

When both the HTML form and the processing PHP code are on the same page (something that is recommended when it comes to prefilling forms), it is important to find out whether a form is just called in the browser (using GET) or if the form is submitted (and the data must be processed).

Checking Whether a Form Has Been Submitted
<?php
  if (isset($_POST['Submit'])) { ...
    echo '<h1>Thank you for filling out this form!
      </h1>';
  } else { ...
?>
  <form method="post" action="<?php echo
     htmlspecialchars($_SERVER['PHP_SELF']); ?>">
    <input type="submit" name="Submit" value="Submit
      form" />
  </form>
<?php
  }
?>

Methd 2: Using empty function
if (!empty($_POST)){
	...
}

You can take several different approaches to this task; something that always works is assigning the Submit button a name and then testing whether this name is present when the form is submitted.

If your form has multiple Submit buttons, give each of them a distinctive name; then, you can check specifically for this name and, therefore, determine which Submit button has been used.

by BrainBellupdated
Advertisement: