Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reCaptcha values not appearing in $_POST

I am trying to use reCaptcha on my site, and recaptcha_challenge_field, and recaptcha_response_field are not being added to the $_POST array on the backend - but the rest of the variables from my form are.

Any ideas? I have double checked the public/private keys.

Here is the generated HTML:

 <form action='myform.php' name='myform' id='myform' method='post' enctype='multipart/form-data'>
    <tr class='select'>
      <td class='label'>Name:</td>

      <td>
        <input type='text'  name='name'  id='name'  class='inputtext'  maxlength='25'  size='25' >
      </td>
    </tr>
    <tr class='select'>
      <td class='label'>Email:</td>
      <td>
        <input type='text'  name='email'  id='email'  class='inputtext'  maxlength='25'  size='25' >

      </td>
    </tr>
    <tr class='select'>
      <td class='label'>Message:</td>
      <td>
        <textarea class='inputtext' name='message'  rows='10' cols='45'></textarea>
      </td>
    </tr>

    <tr class='select'>
      <td class='label'>Are you human?</td>
      <td>
        <script type="text/javascript" src="http://api.recaptcha.net/challenge?k=MY_KEY"></script>

    <noscript>
        <iframe src="http://api.recaptcha.net/noscript?k=MY_KEY" height="300" width="500" frameborder="0"></iframe><br/>
        <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
        <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
    </noscript>
      </td>
    </tr>

    <tr>
      <td>
      &nbsp;
      </td>
      <td style='text-align: left;' colspan='2'>
        <input type='submit' class='button' value='Send message'>
      </td>
    </tr>
  </form>

Here is my handler so far:

print_r($_POST);


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

print_r($resp);

if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
}

Any help would be really appreciated. Thank you,

like image 859
barfoon Avatar asked Dec 29 '22 23:12

barfoon


1 Answers

Conceivably you might be having DOM problems because of the way you're interleaving <table> and <form>. Try moving your <form> and </form> tags outside your <table> and </table> respectively.

like image 155
chaos Avatar answered Jan 08 '23 14:01

chaos