fullyloaded Posted January 12, 2012 Share Posted January 12, 2012 hi i was wondering if anyone had any idea how i can add code A to code b below? code a is my captcha code and code b is my contact form code thanks.. CODE A CAPTCHA: <?php if(isset($_POST["captcha"])) if($_SESSION["captcha"]==$_POST["captcha"]) { echo 'CAPTHCA is valid; proceed the message'; } else { echo 'CAPTHCA is not valid; ignore submission'; } ?> CODE B CONTACT FORM: <? $mailto = "[email protected]"; $cc = ""; $bcc = ""; $subject = "Email subject"; $vname = "blah blah"; $email = $_POST['email']; function validateEmail($email) { if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email)) return true; else return false; } if(strlen($_POST['name']) < 1 || strlen($_POST['message']) < 1 || validateEmail($email) == FALSE) { $emailerror = 'Error:'; if(empty($_POST['name'])) { $emailerror .= '<li>Enter name</li>'; } if(validateEmail($email) == FALSE) { $emailerror .= '<li>Enter valid email</li>'; } if(empty($_POST['message'])) { $emailerror .= '<li>Enter message</li>'; } } else { $emailerror .= "Your email has been sent successfully"; $timestamp = date("F j, Y, g:ia"); $messageproper ="\n\n" . "Name: " . ucwords($_POST['name']) . "\n" . "Email: " . ucwords($email) . "\n" . "Comments: " . $_POST['message'] . "\n" . "\n\n" ; $messageproper = trim(stripslashes($messageproper)); mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() ); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254866-add-captcha-to-contact-form/ Share on other sites More sharing options...
joel24 Posted January 12, 2012 Share Posted January 12, 2012 put all the email sending code within the if where "echo 'CAPTHCA is valid; proceed the message';" is. then change 'echo 'CAPTHCA is not valid; ignore submission';" to a prettier error message for the user to view. Either that or have a look at google's reCAPTCHA Quote Link to comment https://forums.phpfreaks.com/topic/254866-add-captcha-to-contact-form/#findComment-1306825 Share on other sites More sharing options...
fullyloaded Posted January 12, 2012 Author Share Posted January 12, 2012 Thanks joel24 that worked out great! Quote Link to comment https://forums.phpfreaks.com/topic/254866-add-captcha-to-contact-form/#findComment-1307023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.