Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Nov 2003
    Location
    Bloomsbury, London
    Posts
    105
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question How do I validate a Recaptcha form entry please?

    I've installed Recaptcha on a website here

    How can I validate the code in the post PHP please? So, if the user enters an incorrect value in the recaptcha form field, instead of them getting "form accepted", they are asked to enter the correct value?

    I have a "The reCAPTCHA wasn't entered correctly." code from the recaptcha instruction pages in Google.

    The code I added to my form, just above the submit button, is:

    <script type="text/javascript"
    src="http://www.google.com/recaptcha/api/...eaBYhkdidx0Ayg">
    </script>
    <noscript>
    <iframe src="http://www.google.com/recaptcha/api/...eaBYhkdidx0Ayg"
    height="300" width="500" frameborder="0"></iframe><br>
    <textarea name="recaptcha_challenge_field" rows="3" cols="30">
    </textarea>
    <input type="hidden" name="recaptcha_response_field"
    value="manual_challenge">
    </noscript>


    My postinquiry,php file to which form completes are sent is as follows:

    <?php $name = $_REQUEST['name']; $emailadd = $_REQUEST['emailadd']; $lphone = $_REQUEST['lphone']; $mphone = $_REQUEST['mphone']; $postcode = $_REQUEST['postcode']; $timecall = $_REQUEST['timecall']; $reason = $_REQUEST['reason']; $address = $_REQUEST['address']; $time = $_REQUEST['time']; $type = $_REQUEST['type']; $addinfo = $_REQUEST['addinfo']; $addinfo = str_replace ("\n","<BR>",$addinfo); $message = "<table cellpadding=0 cellspacing=0 border=1 style='border-collapse:collapse' width=500> <tr> <td colspan=2 style='font-family:verdana;font-size:15px;font-weight:bold;background-color:#E1F23A' align=center height=30>Inquiry Details</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right> Name:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$name</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Email address:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$emailadd</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Landline Phone:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$lphone</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Mobile Phone:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$mphone</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Address:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$address</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Postcode:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$postcode</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Best Time to Call:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$timecall</td> </tr><tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Reason for selling:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$reason</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Want to sale:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$time</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Property Type:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$type</td> </tr> <tr style='font-family:arial;font-size:11px;'> <td style='font-weight:bold' height=25 width=25% align=right>Additional Info:&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;$addinfo</td> </tr> </table>"; $newLine = "\n"; $to = "info@removed.co.uk,happy@removed.org"; $from = "info@removed.co.uk"; $subject = "Inquiry Details From $name"; $headers = "MIME-Version: 1.0" . $newLine; $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine; $headers .= "From: $from <$from>" . $newLine; if ( @mail($to, $subject, $message, $headers) ) { $error = "Your request has been submitted successfully, one of our advisors will get in touch with you shortly.<P>Should you have any urgent queries, you are welcome to call one of our friendly advisors on <b> 020 3112 9175</b>"; } else { $error = "Inquiry submission failed due to some reason, Please try at later time."; } header( "Location: ./thankyou.php?text=" .$error ) ; include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { echo "The security code entered was incorrect.<br /><br />";
    echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again."; exit; } ?>



    The code provided to me, to add to the above code is:

    require_once('recaptchalib.php');
    $privatekey = "5LdROfUSAAAAAJDXvpqz8vwwKMZac7uA_OZWxU4e";
    $resp = recaptcha_check_answer ($privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);

    if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
    "(reCAPTCHA said: " . $resp->error . ")");
    } else {


    I'm not an expert in PHP, so would greatly appreciate simple instructions on what exactly to do to the above code.

    (I've changed the private key number slightly.)

    Thank you very much for your help!
    Last edited by Azam.net; 06-14-2014 at 12:01 AM. Reason: I've managed to fix it finally!
    Domain Exhibit - premium domain names and websites with significant traffic | quote Coding Forums for additional 15% discount!
    Coding Freebies - free scripts and software worth hundreds of dollars


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •