2

I'm back again. Here is the issue. In implementing ReCaptcha 2.0, I've downloaded file from Github and did all that was instructed (well apparently not or I wouldn't have an issue). My form automatically loads with error showing "missing-input-response" right above the submit button. I can, however, fill out and submit the form and it redirects to the "thank you" page. If I try to submit the form without checking the box, it gives the error (which is good) but the error is there no matter what. What do I need to do? I would really appreciate any help.

Here is my code:

<?php
     require('recaptcha-master/src/autoload.php');

    $siteKey = 'MY SITE KEY';
     $secret = 'MY SECRET KEY';


     $recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\SocketPost());

    $gRecaptchaResponse = $_POST['g-recaptcha-response']; //google captcha post data
    $remoteIp = $_SERVER['REMOTE_ADDR']; //to get user's ip

    $recaptchaErrors = ''; // blank variable to store error

    $resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp); //method to verify captcha
    if ($resp->isSuccess()) {
       // send mail or insert in db or do whatever you wish to

        $emailbody = 'Name: '.$_POST['name']."\n"
        .'Phone: '.$_POST['phone']."\n"
        .'Email: '.$_POST['email']."\n"
        .'Message: '.$_POST['message'];     
        mail('[email protected]', 'More Information', $emailbody);
        echo "<meta http-equiv='refresh' content=\"0; url=thankyou.php\">";


    } else {
       $recaptchaErrors = $resp->getErrorCodes(); // set the error in varible
    }
     ?>

**Here is my form:**  

<form action="contact.php" method="POST" title="Contact us for more information">
                <p><b>Name:<br>
</b>
                    <input name="name" type="text" required id="name" tabindex="1" value="" size="50" maxlength="50"/>
                    <br/> Phone:
                    <br>

                    <input name="phone" type="text" id="phone" tabindex="2" value="" size="50" maxlength="50"/><br/>
                    <b>E-mail:</b><br>
                    <input name="email" type="text" id="email" tabindex="3" value="" size="50" maxlength="25"/><br/>
                    <br>
                    <b>Message:</b><br/>
                    <textarea name="message" cols="60" rows="10" maxlength="150" id="message" tabindex="4"></textarea><br>

                    <br>
                     <div class="g-recaptcha" data-sitekey="MY SITE KEY"></div>
                    <br>
                <?php
                        if ( isset( $recaptchaErrors[ 0 ] ) )
                            echo $recaptchaErrors[ 0 ];

                        ?>
                    <p>&nbsp; </p>
                    <p><input name="submit" type="submit" formmethod="POST" onClick="MM_validateForm('name','','R','phone','','NisNum','email','','RisEmail','message','','R');return document.MM_returnValue" value="Submit">
                    </p>

            </form>
1
  • I still need an answer to this if anyone can help. If it has been answered on this site, I can't find it. Thanks.
    – Newsong80
    Commented Nov 25, 2016 at 12:56

1 Answer 1

1

I found this which is working.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.google.com/recaptcha/api/siteverify?");
curl_setopt($ch, CURLOPT_POST, 1);
$campos=array('secret'=>$secreto,'response'=>$TheResponse);
curl_setopt($ch, CURLOPT_POSTFIELDS,$campos);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ch_exec = curl_exec($ch);
$respuesta_google = json_decode($ch_exec,true);
var_dump($ch_exec);
var_dump($respuesta_google);
curl_close ($ch);

Not the answer you're looking for? Browse other questions tagged or ask your own question.