0

I am trying to implement reCaptcha to my page (HTML and PHP) but for some reason, when I enter the text, it is not working. I have already verified multiple times the private and public keys and I can confirm that they are placed correctly. The error I get back looks just like this: "The reCAPTCHA wasn't entered correctly. Go back and try it again.(reCAPTCHA said: "")" The error method does not return anything, as you can see. Here is the code:

The form:

<form action="ticket.php" method="post">
    <table>
        <tr>
            <td>Full Name:</td> 
            <td><input type="text" name="name" value="<?=(!empty($_POST['name'])) ? $_POST['name'] : ''?>" /></td>
        </tr>
        <tr>
            <td>E-mail:</td> 
            <td><input type="text" name="email" value="<?=(!empty($_POST['email'])) ? $_POST['email'] : ''?>" /></td>
        </tr>
        <tr>
            <td>Topic:</td>
            <td><input type="text" name="topic" value="<?=(!empty($_POST['topic'])) ? $_POST['topic'] : ''?>" /></td>
        </tr>
        <tr></tr>
        <tr>
            <td>Question:</td>
        </tr>
        <tr>
            <td colspan="2"><textarea cols="30" rows="5" name="question" "<?=(!empty($_POST['question'])) ? $_POST['question'] : ''?>"></textarea></td>
        </tr>
        <tr>
            <td colspan="2">
                <?php
                  require_once('recaptchalib.php');
                  $publickey = "public key here";
                  echo recaptcha_get_html($publickey);
                ?>
            </td>
        </tr>
        <br>
        <tr>
            <td colspan="2" style="text-align:center;"><input type="submit" name="submit" value="Submit Question" /></td>
        </tr>
    </table>
</form>

The PHP:

<html>
    <head>
        <title></title>
        <link href='http://fonts.googleapis.com/css?family=Coda|Oranienbaum|Amarante' rel='stylesheet' type='text/css'>
        <link href="css/style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div class="wrapper">
            <h1><a>Contact Us</a></h1>
        </div>
        <div class="sidebar">
            <div class="sBlock">
                <h2>Sidebar</h2>
                <ul>
                    <li><a href="index.php">Home</a></li>
                    <li><a href="about.php">About Us</a></li>
                    <li><a href="tips.php">Tips</a></li>
                    <li><a href="services.php">Services</a></li>
                    <li><a href="contact.php">Contact Us</a></li>
                </ul>
            </div>
        </div>
        <div class="contentBody">
            <div class="post">
                <?
                    require_once('recaptchalib.php');
                    $privatekey = "private key here";
                    $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);

                    $elements = array('name', 'email', 'topic', 'question');
                    $valid = true;
                    $show = true;
                    if(!empty($_POST['submit'])) {
                        foreach ($elements as $e) {
                            if (empty($_POST[$e])) {
                                echo '<div style="color:red;"> The field ' . $e . ' is required.</div><br />';
                                $valid = false;
                            }
                        }
                        if (!$resp->isvalid) {
                            echo '<div style="color:red;"> "The reCAPTCHA wasn\'t entered correctly. Go back and try it again.(reCAPTCHA said: "' . $resp->error . '")"</div><br />';
                            $valid = false;
                        }

                        if ($valid) {
                            echo '<div style="color:red;"> S\'all good.</div><br />';
                        }
                    }
                    include 'ticket_form.php';
                ?>
            </div>
        </div>
        <div class="clearfloat"></div>
        <footer>
            <p class="copyright">
                Copyright &copy; <a href="#"></a>
            </p>
        </footer>
    </body>
</html>
plasmy
  • 99
  • 3
  • 9
  • 32
  • http://stackoverflow.com/questions/3232904/using-recaptcha-on-localhost - is your localhost version working or not? (remember, localhost or 127.0.0.1 only) – Cups Apr 25 '13 at 17:39
  • I am testing directly in the hosting site. – plasmy Apr 25 '13 at 17:46
  • The logical thing to do would be to make the simplest possible form with a reCaptcha and test that on your local server, then var_dump() the output of this class you seem to have installed and be depending upon. What's wrong with just using the examples that Google provides? http://www.google.com/recaptcha – Cups Apr 26 '13 at 07:53

0 Answers0