title: reCAPTCHA Image and Verification in the same index
body: <p>I tried to make reCaptcha work in the same index. I tried this:</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      &lt;form action="index.php" method="post"&gt;
        &lt;?php
          require_once('recaptchalib.php');
          $privatekey = "YOUR_PRIVATE_KEY_HERE";
          if (isset($_POST['submit'])) {
            $resp = recaptcha_check_answer ($privatekey,
              $_SERVER["REMOTE_ADDR"],
              $_POST["recaptcha_challenge_field"],
              $_POST["recaptcha_response_field"]);
  
            if (!$resp-&gt;is_valid) {
              echo "&lt;script language='javascript'&gt;
                window.alert('Sorry cannot send email as you have failed to provide correct captcha! Try again...')
              &lt;/script&gt;";
            } else {
              echo "&lt;script language='javascript'&gt;
                window.alert('Thank you for submitting the track. We will be in touch with you very soon. Click Ok to redirect you to the Homepage.')
              window.location.href='http://www.xmasterofficial.tk/'
             &lt;/script&gt;";
            }
         }
         $publickey = "YOUR_PUBLIC_KEY_HERE";
         echo recaptcha_get_html($publickey);
        ?&gt;
       &lt;br/&gt;
       &lt;input type="submit" value="submit" /&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>The problem</strong></p>
  
  <p>The <code>window.alert</code> and <code>window.location.href</code> are not working even if the answer is right or wrong.</p>
  
  <p>When you click the Submit button it should popup an window.alert if the answer is good and redirect to homepage or popup a <code>window.alert</code> to retry if the answer is wrong.</p>
  
  <p>Edit: You can run it. You need recaptchalib.php from google (link: <a href="https://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest" rel="nofollow">https://code.google.com/p/recaptcha/downloads/list?q=label:phplib-Latest</a>)</p>