Registration form - Checking if data entered ($_SERVER['PHP_SELFf'])

What I want to do is,

  1. User comes to registration form.
  2. Fills it , press enter, registration goes on.
  3. If he doesnt fill it, echo Data Missing.

Where I am stuck,

  1. Using isset, it echos Data Missing at the first visit itself which shouldnt happen.

Any suggestions?

I am not looking for any codes as I want to learn it up myself. Just the idea would do.


On the first form load, check the contents of $_SERVER['REQUEST_METHOD']

  // Verify the form has been filled in 
  // If any are missing, display missing data message
  // and display the form again
else {
  // Just display the form for the first time

I also recommend reading up on the post-redirect-get pattern, wherein you display the form from a script which does no form processing itself. The form posts to another handler script (rather than back to itself), which does all the validation and action, and finally redirects to a new location or back to the original form on error or incomplete data.

Read more about the $_SERVER superglobal array.

Can you put the "action" code in another page?

That's what I normally due, mostly to prevent the user from resubmitting the data on a page refresh, but it would also resolve your issue.

Alternatively, you could take into consideration PHP upload - Why isset($_POST['submit']) is always FALSE in which they make some valid points about the isset function.

Need Your Help

Regex to find strings with only letters or numbers or both

ruby regex

I am searching for strings with only letters or numbers or both. How could I write a regex for that?