Jump to content

validation


westminster86

Recommended Posts

when leaving the form blank i get the error message from the first if statment. But even when i do add values into the two fields i still get the error message? what am i doing wrong? the two varibales have values becuase ive checked with echo statments

 

<?php


$email = $_POST['uemail'];
$password = $_POST['upassword'];


try
{

  if(!filled_out($_POST))
  {
    throw new Exception('You have not filled the form out correctly - please go back and try again.');
  }

  if(!valid_email($email))
  {
    throw new Exception('That is not a valid email address. Please go back and try again.');
  }

  if(strlen($password)<6)
  {
    throw new Exception('Your password must be at least 6 characters long. Please go back and try again');
  }
}
catch (Exception $e)
{
  echo $e->getMessage();
  exit;
}

function filled_out($form_vars)
{
  foreach ($form_vars as $key => $value)
  {
    if (!isset($key) || ($value == ''))
      return false;
  }
  return true;
}

function valid_email($address)
{
  if (ereg('^[a-zA-Z0-9 \._\-]+@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z+$', $address))
    return true;
  else
    return false;
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.