Validation error

I have made a Email form, on which i have putted a recaptcha control, and some textboxes. The problem is the validation code o have putted works great at the localhost. The email field makes error when i have put some this kind of thing “fff”. And also the recaptcha makes error if its not validated.The validation code is

[php]<?php
if(isset($_POST[‘Submit1’]))
{
$errCapt = “”;
require_once(‘recaptchalib.php’);

$privatekey = “my key”;

$resp = recaptcha_check_answer ($privatekey, $_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);
if (!$resp->is_valid) {
$errCapt = ‘

The reCAPTCHA was not entered correctly.

’;
}
}
?> <?PHP $errName = ""; $errEmail = ""; $errComments = ""; $errSubj = ""; if(isset($_POST['Submit1'])) { // Full Name must specified if(empty($_POST["FName"])) $errName = '

Name must be specified.

'; if(empty($_POST["Subjt"])) $errSubj = '

Subject Line must be specified.

'; // Comments must be there if(empty($_POST["Comments"])) $errComments = '

Provide Comments to send in Mail.

'; // Email mask if(preg_match("/^[a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/", $_POST["Email"]) === 0) $errEmail = '

Provide a valid Email Address.

'; $message = strip_tags($_POST['Comments']); $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name']))); $filename = $_FILES['file']['name']; $boundary =md5(date('r', time())); $headers = "From: [email protected]\r\nReply-To: [email protected]"; $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\""; $message="This is a multi-part message in MIME format. --_1_$boundary Content-Type: multipart/alternative; boundary=\"_2_$boundary\" --_2_$boundary Content-Type: text/plain; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit $message --_2_$boundary-- --_1_$boundary Content-Type: application/octet-stream; name=\"$filename\" Content-Transfer-Encoding: base64 Content-Disposition: attachment $attachment --_1_$boundary--"; $Email=$_POST['Email']; $Subj=$_POST['Subjt']; if(mail($Email,$Subj,$message,$headers)) { header("Location:Thank.php"); } Else {print("Email Sending Failed");} } ?> [/php]

As, i have put the code on Server, validation doesnot work properly, Capthcha is not validated, if i put some wrong email, it even send the email. Please!!

Well, Madiha,
It looks like your test for validation is only set up to check for it and does nothing.
You need to add what you want done when it works. In the first part of your posted code, (between <? and ?>) you test for the captcha, then do nothing. You need to check for validation and then do the results. If the validation fails, then echo the error and DIE. If it works then, do the second part of our code which sends the email. The sending of the email should be inside your ELSE for the captcha check…
If (captch fails) [
DO this code…
}ELSE{
create and send the emal…
}
Hope this helps. If not read this site, it has all you need to learn about PHP Captcha’s:
http://code.google.com/apis/recaptcha/docs/php.html

Sponsor our Newsletter | Privacy Policy | Terms of Service