Tuesday, July 20, 2010

PHP: Check to see if you have a postback.

I looked all over for a simple answer to find out how you check to see if the page is a postback. It was simple, but yet out of all the web pages I trolled through nothing had come up.

The situation is that if you submit a form and the action is set to blank, then how do you do some work if there is postback data and do other work if there is no postback data? This a common occurrence that I came across all the time while doing development in the .NET world, but there was a simple boolean variable to check in C#. How do you do that in PHP?

if ($_POST) {

}

It IS that simple (well, at least for me it was). It just checks to see if the $_POST array has been set. I don't know why no one else can answer that simple question just like that.