Ideally, you do NOT check a form in php: you check it in javascript BEFORE submitting to php!
The way to do it is NOT to send the form with "submit" button, but to use a button that calls a javascript function:
function js_validate(theForm)
{
var em = theForm.element['email'];
var email = em.value;
if (echeck(email))
{
alert ("Invalid email address");
em.focus();
return(true);
}
etc...: your other checks.
all checks pass:
theForm.submit(); => you submit the form!
}
// === EMAIL VALIDATION ====
function echeck(str)
// (the variable "str" is the full email address)
// returns true if not valid, false if valid
{
var at="@"
var dot="."
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (str.indexOf(at)==-1)
return(true);
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
return(true);
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
return(true);
if (str.indexOf(at,(lat+1))!=-1)
return(true);
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
return(true);
if (str.indexOf(dot,(lat+2))==-1)
return(true);
if (str.indexOf(" ")!=-1)
return(true);
return (false);
}
For the other checks, just get the element and check against "" (blank)
Return to the field if it is blank (fieldname.focus() )