Jump to content

user validation and errors


Bala

Recommended Posts

<?php /* this is guarunteed to work it is possible to use <? (short tags but this style works everywhere).*/

/*Only verify/validate form when it is submitted program name: form.php */

if(isset($_POST[submit])){

  $error='';//initialize $error to blank

  if(trim($_POST[username])=='' || strlen(trim($_POST[username])) < 6 ||strlen(trim($_POST[username])) >12){

      $error.="Please enter a username between 6 and 12 characters!<br />"; //concatenate the $error Message with a line break

  }

  if(trim($_POST[password])=='' || strlen(trim($_POST[password]))< 6){

      $error.="Your password must be at least 6 characters in length!<br />";//concatenate more to $error 

  }

  if(trim($_POST)==''){

    $error.="An email address is required!<br />";

  }

      else {

        if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST)) {

        $error="The e-mail you entered was not in the proper format!";

       

        }

    }

  if($error==''){//Hmmmm no text is in $error so do something else, the page has verified and the email was valid

  // so uncomment the line below to send the user to your own success page or wherever (swap yourpage.php with your files location).

  //echo "script type=\"text/javascript\">window.location=\yourpage.php\"<script>"; 

  }

    else{

      echo "<span style=color:red>$error</span>";

    }               

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.