Professional Documents
Culture Documents
Index.php file
<html>
<head>
<link rel="stylesheet" type="text/css" href="tc2cval.css">
</head>
<body>
<?php
if($_SERVER['REQUEST_METHOD'] = 'POST'){
if(empty($_POST['user'])){
$user_err = "name is empty";
}else if(!preg_match("/^[a-z A-Z]*$/",$_POST['user'])){
$user_err = "only characters are allowed";
}
if(empty($_POST['eml'])){
$email_err = "email is empty";
}else if(!filter_var($_POST['eml'],FILTER_VALIDATE_EMAIL)){
$email_err = "email is NOt correct";
}
if(empty($_POST['num'])){
$num_err = "number is empty";
}else if(!preg_match("/^[0-9]{10}$/",$_POST['num'])){
$num_err = "only 10 digits are allowed";
}
if(empty($_POST['pass'])){
$pass_err = "password is empty";
}else{
if((strlen($_POST['pass'])<2) || (strlen($_POST['pass'])>9)){
$pass_err = " enter password is between 2 to 9";
}
}
if(empty($_POST['cpass'])){
$cpass_err = "confirm password is empty";
}else if($_POST['pass'] != $_POST['cpass']){
$cpass_err = "password and confirm password is not matched";
}
if(empty($_POST['ur'])){
$url_err = "url is empty";
}
if(empty($_POST['text'])){
$cm_err = "comment is empty";
}
if(empty($_POST['gen'])){
$gen_err = "gender is empty";
}
}
?>
<label>Enter Email:</label><br>
<input type= "text" name="eml" id="eml" value='<?php echo
isset($_POST['eml']) ? $_POST['eml'] : '';?>'><br>
<span class="err"><?php echo $email_err; ?></span><br>
<label>Enter Number:</label><br>
<input type= "text" name="num" id="num" value='<?php echo
isset($_POST['num']) ? $_POST['num'] : '';?>'><br>
<span class="err"><?php echo $num_err; ?></span><br>
<label>Enter Password</label><br>
<input type= "password" name="pass" id="pass" value='<?php echo
isset($_POST['pass']) ? $_POST['pass'] : '';?>'><br>
<span class="err"><?php echo $pass_err; ?></span><br>
<label>Enter Url</label><br>
<input type= "url" name="ur" id="ur" value='<?php echo
isset($_POST['ur']) ? $_POST['ur'] : '';?>'><br>
<span class="err"><?php echo $url_err; ?></span><br>
<label>Enter Comments</label><br>
<textarea rows="5" cols="10" name="text" id="text"><?php echo
isset($_POST['text']) ? $_POST['text'] : '';?></textarea><br><br>
<span class="err"><?php echo $cm_err; ?></span><br>
<label>Select Gender</label><br>
<input type= "radio" name="gen" <?php if (isset($_POST['gen']) &&
$_POST['gen']=="male") echo "checked";?> value="male">Male
<input type= "radio" name="gen" <?php if (isset($_POST['gen']) &&
$_POST['gen']=="female") echo "checked";?> value="female">Female
<input type= "radio" name="gen" <?php if (isset($_POST['gen']) &&
$_POST['gen']=="others") echo "checked";?> value="others">others<br>
<span class="err"><?php echo $gen_err; ?></span><br>
?>
</body>
</html>
Validation.css
#unm,#eml,#pass,#cpass,#ur,#num{
width: 40%;
height:30px;
background-color: #ddd;
}
#text{
width: 40%;
height: 50px;
background-color: #ddd;
}
#btn{
width: 40%;
height:30px;
background-color: green;
}
.err{
color: red;
}