17 August 2013

PHP Check If Form Submitted

There are several ways to check whether a form submitted or not.

if(isset($_POST))
{
// do work
}

if (!empty($_POST))
{
// do work
}
 

But it is much better to check the server parameter. There are pretty much information stored in $_SERVER.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
{
// now we are pretty sure for the post action 
}
 
 


Request method is just more rock solid way to check is a form submitted or not.

No comments: