Hi All - I am trying to correctly valididate forms on serverside using PHP and on client side with JavaScript I seem to have got lost in the processes here.
Thanks
DJ
<?php
// define variables and initialize with empty values
$fname = "";
$fnameErr ="";
$lname = "";
$lnameErr ="";
$pass ="";
$passErr="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["fname"])) {
$fnameErr = "Missing";
}
else {
$firstname = $_POST["fname"];
}
if (empty($_POST["lname"])) {
$lnameErr = "Missing";
}
else {
$lastname = $_POST["lname"];
}
if (empty($_POST["pass"])) {
$passErr = "Missing";
}
else {
$password = $_POST["pass"];
}
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form name="myForm" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<label for="fname">First name: </label>
<input type="text" name="fname" value="<?php echo htmlspecialchars($fname);?>" onblur=" if (this.value.length <2) { alert('Please enter a value that is at least 2 characters long.'); this.focus(); }" >
<br />
<label for="lname"> last name: </label>
<input type="text" name="lname" value="<?php echo htmlspecialchars($lname);?>" onblur=" if (this.value.length <2) { alert('Please enter a value that is at least 2 characters long.'); this.focus(); }" >
<br />
<label for="password">Password: </label>
<input name="pass" type="password" onblur=" if (this.value.length < 5) { alert('Please enter a value that is at least 5 characters long.'); this.focus(); }">
<br />
<input type="submit" value="Submit">
</form>
</body>
</html>