Hello,
My name is Andres and I am new to php and to this forum as well.
My problem is that I can not figure out, why my validate email check always shows error no matter what (field is empty, random letters on field or a real valid email)
Here is my code:
[php]
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = “E-mail address not valid!”;
}
[/php]
Before that I also tried this:
[php]
if (!preg_match ("/([\w-]+@[\w-]+.[\w-]+)/", $email)) {
$errors[] = “E-mail address not valid!”;
}
[/php]
This is how I call an error.
[php]
[/php]
I figured that with the first code I used, it will always add something to array, either it is true or false and because I check if $errors is empty it will show error even if it is not true.
I am not sure if the filter_var function does the same thing but I suspect it does.
Is there a way I can make something different to keep array empty in case email is valid and make the code work correctly?
If you need to see my whole code, you can check from
github.com/andressoop/Pood-2.0
Files that include bits from my contact form:
Pood-2.0 / controllers / contact.php
Pood-2.0 / views / contact_index_view.php
Pood-2.0 / functions.php