Saturday, January 2, 2016

form validation


<?php
$m ="";
$em ="";
$ma ="";
$pa ="";
if(isset($_POST['sub'])){
$name = $_POST['name'];
$email = $_POST['em'];
$upass = $_POST['upass'];
$repass = $_POST['repass'];
$len = strlen($name);
if(empty($name)&& empty($email) && empty($upass)&& empty($repass)){
$m = "Form should not blank!!";
}
if($len <4 || $len >8){$ma = "Name should be 4 to 8 character!!";}
else{$ma = "valid name!!";}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
$em = "invalid email format";
} else {$em = "valid email";}

if((strcmp($upass,$repass)!==0) || empty($upass) || empty($repass))  {
$pa = "password do not match!!";
}else{$pa = "password  match!!";}
}
?>



<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>

</head>

<body>
<div class="formdiv"><br><br>
<form  method="post">
Name:
<input type="text" name="name" size="30" value="<?php if(isset($name)) echo $name?>">
<span><?php echo $ma;?></span><br>
Email:
<input type="text" name="em" size="30" value="<?php if(isset($email)) echo $email; ?>">
<span><?php echo $em;?></span><br>
Password:
<input type="password" name="upass" size="30"><br>
PasswordRetype:
<input type="password" name="repass" size="30">
<span><?php echo $pa;?></span><br><br>
<input type="submit" name="sub" value="Register">
<input type="reset" name="res" value="Reset">
</form>
<h1><?php if($m) echo $m?></h1>


</div>
</body>
</html>

No comments:

Post a Comment