Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if form has been submitted - PHP

People also ask

How do you check form is submitted or not in jquery?

$("#something-%"). submit(function(e) { e. preventDefault(); $("#some-span"). html(data); });

How can get submit button value in PHP?

Add type property with submit type="submit" to button tag this will submit the form then receive the form inputs value in php script with super global variable $_POST['input name'] or $_GET[] wdepends on from action property value by default GET.


For general check if there was a POST action use:

if (!empty($_POST))

EDIT: As stated in the comments, this method won't work for in some cases (e.g. with check boxes and button without a name). You really should use:

if ($_SERVER['REQUEST_METHOD'] == 'POST')

How about

if($_SERVER['REQUEST_METHOD'] == 'POST')

Actually, the submit button already performs this function.

Try in the FORM:

<form method="post">
<input type="submit" name="treasure" value="go!">
</form>

Then in the PHP handler:

if (isset($_POST['treasure'])){
echo "treasure will be set if the form has been submitted (to TRUE, I believe)";
}

Use

if(isset($_POST['submit'])) // name of your submit button

if ($_SERVER['REQUEST_METHOD'] == 'POST').