Hi guys!
Hope someone can help me out here. I'm using javascript to validate a form and if it's false it displays a message. If it's true in passes it to a php file to process it.
The problem im having is even if it fails validation it still passes to the php file.
You can see it here: http://www.darawebdesign.com/projects/login_script/
The code im using is:
function validate_required(field,alerttxt){
with (field){
if (value==null||value==""){
document.getElementById("empty").style.display="block";
return false;
}
else{
return true;
}
}
}
function validate_email(field,alerttxt){
with (field){
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2){
alert(alerttxt);
return false;
}
else{
return true;
}
}
}
function validate_login(thisform){
with (thisform){
if (validate_required(user,"Name must be filled out!")==false){
name.focus();
return false;
}
if (validate_required(pass,"Password must be filled out!")==false){
comment.focus();
return false;
}
}
}
<form name = "login_form" action = "includes/verify_login.php" method = "POST" onsubmit="return validate_login(this)">
<label for="user">User Name: </label><input type="text" class="custom_field" name="user" id="user">
<label for="pass">Password: </label><input type="password" class="custom_field" name="pass" id="pass">
<input type="checkbox" id="remember" name="remember"><label id="label_remember" for="remember">Remember Me</label><br>
<button id="custom_button">Login</button>
</form>