Using bAjax for form validation. (This demo will show you how to work together with jQuery as well):
Please click on "Submit" button if you're done:
Sign Up:
JavaScript:
HTML:
Please click on "Submit" button if you're done:
Sign Up:
PHP:
/** validate user sign up form **/
if(isset($_POST["action"]) && $_POST["action"] == 1)
{
$emailAdress = trim($_POST["email_address"]);
$firstName = trim($_POST["first_name"]);
$lastName = trim($_POST["last_name"]);
$gender = $_POST["gender"];
// going to validate and return result
if($emailAdress == "" || $emailAdress == NULL)
{
echo "Error: Email address is empty!||email_address";
}
elseif($emailAdress != "" || $emailAdress != NULL)
{
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $emailAdress))
{
if($firstName == "" || $firstName == NULL)
echo "Error: First name is empty!||first_name";
elseif($lastName == "" || $lastName == NULL)
echo "Error: Last name is empty!||last_name";
elseif($gender == "-")
echo "Error: Please select your gender!||gender";
else
echo "Congratulations! You have just completed the Sign Up.||OK";
} else
{
echo "Error: Invalid email address.||email_address";
}
}
}// end if submitted