tags:

views:

108

answers:

1

I have implemented a captcha in my form, but it doesn't seem to be validating. I have included code below to see if there is anything obvious in my layout and how I can go about modifying it. Public and private keys have been deleted for the post.

Thanks.

<h1>Contact</h1>
<form action="index.php" method="post">
<input type="hidden" name="required_fields" value="name, email, message" />
<input type="hidden" name="email_fields" value="email" />
<input type="hidden" name="html_template" value="form.tpl.html" />
<input type="hidden" name="mail_template" value="mail.tpl.txt" />
<input type="hidden" name="thanks" value="/thanks.php" />
<!-- <input type="hidden" name="error_page" value="./docu/error.html" /> -->
<table border="0" cellpadding="3" cellspacing="0">
<tr>
  <td><p>Full Name <span>*</span></p></td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><input type="text" name="name" value="" size="40" /></td>
</tr>
<tr valign="bottom">
  <td><p>Phone</p></td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><input type="text" name="phone" value="" size="40" />
  </td>
</tr>
<tr valign="bottom">
  <td><p>Email <span>*</span></p></td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><input type="text" name="email" value="" size="40" />
  </td>
</tr>
<tr valign="top">
  <td><p>Message <span>*</span></p></td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><textarea name="message" cols="30" rows="10"></textarea></td>
</tr>
<tr valign="top">
  <td>&nbsp;</td>
  <td>&nbsp;&nbsp;&nbsp;</td>
  <td><p>

<?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "";
$privatekey = "";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);

    if ($resp->is_valid) {
            echo "You got it!";
    } else {
            # set the error code so that we can display it
            $error = $resp->error;
    }
}
echo recaptcha_get_html($publickey, $error);
?>  
      <input type="submit" name="send" value="Send" />
      <br />
      <span>*</span> = required field.</p></td>
</tr>
</table>
</form>
A: 

I cannot say what is wrong with your captcha, because I don't know the specifics of this captcha implementation.

Your form is reset because you do not fill the fields with posted data. Perhaps you do not intend to.

First make sure your form works as expected without the captcha, to make sure the problem is in the captcha.

dyve