Hello, I’m trying to validate a contact form, first I check if the first name = last name then I throw an error which works fine, then I verify the email address if the domain of that address is blacklisted, I have an array with all blacklisted domains.
So here is my test:
First name = last name + blacklist email address domain name = OK, it will redirect the user back to the homepage
First name is not equal to the Last name + Blacklist email address domain name = OK, I get redirected to the home page
First name is not equal to the last name + Not Blacklisted email address = NOT OK, it will throw an error : Email is a required field.
Here is my code:
//Validate data
if ($firstname != '') {
if (!Validate::isName($firstname)) {
$this->errors[] = $this->module->l('First name is not valid.', 'createticket');
}
} else {
$this->errors[] = $this->module->l('First name is required field.', 'createticket');
}
if ($lastname != '') {
if (!Validate::isName($lastname)) {
$this->errors[] = $this->module->l('Last name is not valid.', 'createticket');
}
else if ($firstname == $lastname ) {
$this->errors[] = $this->module->l('First name and last name matches, doesn\t make sense!', 'createticket');}
} else {
$this->errors[] = $this->module->l('Last name is required field.', 'createticket');
}
if ($email = (in_array(substr($email, strrpos($email, '@') + 1), $RefusedDomains))) {
header('Location: https://google.com');}
if ($email != '') {
if (!Validate::isEmail($email)) {
$this->errors[] = $this->module->l('Email is not valid.', 'createticket');
}
} else {
$this->errors[] = $this->module->l('Email is required field.', 'createticket');
}