Simple Form Validation With Error Message

Project: Simple Form Validation With Error Message

<?php 

extract($_REQUEST);
function data_trim($data){
	$data = trim($data);
	$data = strip_tags($data);
	$data = htmlspecialchars($data);
	return $data;
}

if (isset($signup)) {
	$fname = Data_trim($fname);
	$lname = Data_trim($lname);
	$email = Data_trim($email);
	$password = Data_trim($password);
	$confirm = Data_trim($confirm);


// checking the all variable is empty or not
	if (!empty($fname) || !empty($lname) || !empty($email) || !empty($password) || !empty($confirm)) {
		
		if (!empty($fname)) {
			if (!empty($lname)) {
				if (!empty($email)) {
					if (!empty($password) || !empty($confirm)) {
						if ($password == $confirm) {
							// now store this data to database and show on same page.........
						}else{
						// if $password & $confirm is empty
					$error1 = "<font color='red'>Please Check Your Password That You Input</font>";
						}
						
					}else{
					// if $password & $confirm is empty
					$error1 = "<font color='red'>Please Fill Up Password & Confirm Password</font>";
					}
				}else{
					// if $email is empty
					$error1 = "<font color='red'>Please Fill Up Email</font>";
				}
			}else{
				//if $lanme is empty
				$error1 = "<font color='red'>Please Fill Up Last Name</font>";
			}

		}else{
			//if $fname is empty
		$error1 = "<font color='red'>Please Fill Up First Name</font>";
		}
	}else{
		// if all variable is empty 
		$error = "<font color='red'>* Please Fill Up All Details</font>";
		}
}

?>


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Form Submit</title>
</head>
<body>

<form action="" method="">
	<table>
		<tr>
			<td>
				<?php echo $retVal = (isset($error)) ? $error : '';
				echo $retVal1 = (isset($error1)) ? $error1 : '';


				?>
			</td>
		</tr>
		<tr>
	<td>First Name:</td>
	<td><input type="text" name="fname"></td>
	</tr>
	<tr>
	<td>Last Name:</td>
	<td><input type="text" name="lname"></td>
	</tr>
	<tr>
	<td>Email:</td>
	<td><input type="email" name="email"></td>
	</tr>
	<tr>
	<td>Password:</td>
	<td><input type="password" name="password"></td>
	</tr>
	<tr>
	<td>Confirm Password:</td>
	<td><input type="password" name="confirm"></td>
	</tr>
	<tr>
		<td>
	<input type="submit" value="Sign Up" name="signup">
		</td>
	</tr>
	</table>
</form>
</body>
</html>

1 Comment

Leave a Reply

Your email address will not be published.


*