Hi
I’m having a strange problem with the validation of a contact form. It looks like that
if (strlen(trim($_POST['message']) == 0))
is not working as it should.
Here is my code
[php]
<?php include "lib/configuration.php"; include "language/frontend/portuguese.php"; include "templates/frontend/header.tpl"; //If the form is submitted if(isset($_POST['submit'])) { $isError = False; //Check to make sure that the name field is not empty if (strlen(trim($_POST['contactname']) == 0)) { debug("is error in contactname: ", trim($_POST['contactname'])); debug("lengh: ", (strlen(trim($_POST['contactname'])))); $isError = true; } else { debug("no error in contactname: ", trim($_POST['contactname'])); debug("lengh: ", (strlen(trim($_POST['contactname'])))); $name = trim($_POST['contactname']); } //Check to make sure that the subject field is not empty if (strlen(trim($_POST['subject']) == 0)) { debug("is error in subject: ", trim($_POST['subject'])); debug("lengh: ", (strlen(trim($_POST['subject'])))); $isError = true; } else { debug("no error in subject: ", trim($_POST['subject'])); debug("lengh: ", (strlen(trim($_POST['subject'])))); $subject = trim($_POST['subject']); } //Check to make sure sure that a valid email address is submitted if (strlen(trim($_POST['email']) == 0)) { debug("is error in email: ", trim($_POST['email'])); debug("lengh: ", (strlen(trim($_POST['email'])))); $isError = true; } else if (!filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL)) { $isError = true; } else { debug("no error in email: ", trim($_POST['email'])); debug("lengh: ", (strlen(trim($_POST['email'])))); $emailFrom = trim($_POST['email']); } //Check to make sure comments were entered if (strlen(trim($_POST['message']) == 0)) { debug("is error in message: ", trim($_POST['message'])); debug("lengh: ", (strlen(trim($_POST['message'])))); $isError = true; } else { if (function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { debug("no error in message: ", trim($_POST['message'])); debug("lengh: ", (strlen(trim($_POST['message'])))); $comments = trim($_POST['message']); } } //If there is no error, send the email if ($isError = false) { $emailTo = $adminemail; $body = "Name: $name \n\nEmail: $emailFrom \n\nSubject: $subject \n\nComments:\n $comments"; $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $emailFrom; mail($emailTo, $subject, $body, $headers); echo ""; echo "[/php]
The log of the debugger I setup is this
[php]
2013-06-22 14:06:49 - is error in contactname: : Virginio Reis
2013-06-22 14:06:49 - lengh: : 13
2013-06-22 14:06:49 - is error in subject: : Teste
2013-06-22 14:06:49 - lengh: : 5
2013-06-22 14:06:49 - is error in email: : [email protected]
2013-06-22 14:06:49 - lengh: : 16
2013-06-22 14:06:49 - is error in message: : mensagem de teste
2013-06-22 14:06:49 - lengh: : 17
[/php]
What is wrong with this code? Can someone help me_
Thank You