I'm trying to make a test PHP login page which tests whether the user has entered an email and a password and then redirects to another page. I have used a piece of pre-coded login page (HTML part below) in which there is a form made for email and passwords.
<form action = "" method = "post">
<label>Mail:</label><br/>
<input type="email" placeholder="Enter your email"><br><br>
<label>Password:</label><input type = "password" name = "password" class = "box" /><br/><br />
<input type = "submit" value = " Ok "/><br />
<button onclick="location.href='http://www.google.com'" type="button">Ok</button>
</form>
Is it possible to check the entered value on whether it's an email or not?
you can do this
after you post your form values to the server page
just use if conditions and pattern match(for email)
$password= test_input($_POST["password"]);
if(empty($password)){
$err[]='password Required';
}
if (!preg_match("/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,12}$/",$password)) {
$err[]= "Only letters and white space allowed";
}
if (empty($_POST["email"])) {
$err[]= "Email is required";
} else {
$email= test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$err[]= "Invalid email format";
}
}
if(!empty($err)){
//// echo "email or password error//
var_dump($err);
}else{
///do your success
}
tinker a bit