title: How can I validate a hCaptcha in the same page and afterwards redirrect the answer to post/ajax.php?
body: <p>I use a script written by somebody else and I don't know javascript at all.
  The following usecase I want to change: if you press for a button, it will be displayed a modal with a captcha in it. After you validate the captcha, the page proceeds with some datas for ajax.php. I have the code that works for the previous captcha implemented, but I want to do it through hCaptcha.</p>
  <pre><code>    function goShortlink(sid) {
          $('#goShortlink').modal({backdrop: 'static', keyboard: false});
          $('.captcha-holder').CBCaptcha({
              clickDelay: 500,
              invalidResetDelay: 2500,
              requestIconsDelay: 1500,
              loadingAnimationDelay: 1500,
              hoverDetection: true,
              enableLoadingAnimation: true,
              validationPath: 'system/libs/captcha/request.php'
          }).bind('success.CBCaptcha', function(e, id) {
              validateShortlink(sid);
          });
      }&quot;;
  </code></pre>
  <p>and the validation path from system/libs/captcha/request.php is</p>
  <pre><code>&lt;?php
  session_start();
  require('session.class.php');
  require('captcha.class.php');
  
  if((isset($_GET['hash']) &amp;&amp; strlen($_GET['hash']) === 48) &amp;&amp;
      (isset($_GET['cid']) &amp;&amp; is_numeric($_GET['cid'])) &amp;&amp; !isAjaxRequest()) {
      CBCaptcha::getIconFromHash($_GET['hash'], $_GET['cid']);
      exit;
  }
  
  if(!empty($_POST) &amp;&amp; isAjaxRequest()) {
      if(isset($_POST['rT']) &amp;&amp; is_numeric($_POST['rT']) &amp;&amp; isset($_POST['cID']) &amp;&amp; is_numeric($_POST['cID'])) {
          switch((int)$_POST['rT']) {
              case 1:
                  $captcha_theme = (isset($_POST['tM']) &amp;&amp; ($_POST['tM'] === 'light' || $_POST['tM'] === 'dark')) ? $_POST['tM'] : 'light';
  
                  header('Content-type: application/json');
                  exit(CBCaptcha::getCaptchaData($captcha_theme, $_POST['cID']));
              case 2:
                  if(CBCaptcha::setSelectedAnswer($_POST)) {
                      header('HTTP/1.0 200 OK');
                      exit;
                  }
                  break;
              default:
                  break;
          }
      }
  }
  
  header('HTTP/1.1 400 Bad Request');
  exit;
  
  function isAjaxRequest() {
      return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
  }
  </code></pre>
  <p>?&gt;</p>
  <p>How can I modify it for holding the modal until hCaptcha is validated and then proceeding with the validation ? I have the rest of the code as well, but I don't know if it is not important for our problem. If you need it please tell me.</p>
  <p>Thanks for your kindness and help!</p>