Magento 1.9 : Validate the Google reCaptcha in custom popup












0















I have added the google recaptcha in custom popup. But, form is also submitting without captcha.



I have used following codes for captcha:



 <script src='https://www.google.com/recaptcha/api.js'></script>
<div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>


I have also used js code for validating. But, I think it's not proper way to validate it.



=> js code :



function checkcaptcha() {
if((jQuery('#g-recaptcha-response').val())=='') {
jQuery('.captcha-error').css('display','block');
return false;
} else {
jQuery('.captcha-error').css('display','none');
}

}


Please help me for validating reCaptcha in proper way.



Thanks.



Note : Do not suggest any extension link here. I want to check programmatically.










share|improve this question
















bumped to the homepage by Community 13 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    I have added the google recaptcha in custom popup. But, form is also submitting without captcha.



    I have used following codes for captcha:



     <script src='https://www.google.com/recaptcha/api.js'></script>
    <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>


    I have also used js code for validating. But, I think it's not proper way to validate it.



    => js code :



    function checkcaptcha() {
    if((jQuery('#g-recaptcha-response').val())=='') {
    jQuery('.captcha-error').css('display','block');
    return false;
    } else {
    jQuery('.captcha-error').css('display','none');
    }

    }


    Please help me for validating reCaptcha in proper way.



    Thanks.



    Note : Do not suggest any extension link here. I want to check programmatically.










    share|improve this question
















    bumped to the homepage by Community 13 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      I have added the google recaptcha in custom popup. But, form is also submitting without captcha.



      I have used following codes for captcha:



       <script src='https://www.google.com/recaptcha/api.js'></script>
      <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>


      I have also used js code for validating. But, I think it's not proper way to validate it.



      => js code :



      function checkcaptcha() {
      if((jQuery('#g-recaptcha-response').val())=='') {
      jQuery('.captcha-error').css('display','block');
      return false;
      } else {
      jQuery('.captcha-error').css('display','none');
      }

      }


      Please help me for validating reCaptcha in proper way.



      Thanks.



      Note : Do not suggest any extension link here. I want to check programmatically.










      share|improve this question
















      I have added the google recaptcha in custom popup. But, form is also submitting without captcha.



      I have used following codes for captcha:



       <script src='https://www.google.com/recaptcha/api.js'></script>
      <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>


      I have also used js code for validating. But, I think it's not proper way to validate it.



      => js code :



      function checkcaptcha() {
      if((jQuery('#g-recaptcha-response').val())=='') {
      jQuery('.captcha-error').css('display','block');
      return false;
      } else {
      jQuery('.captcha-error').css('display','none');
      }

      }


      Please help me for validating reCaptcha in proper way.



      Thanks.



      Note : Do not suggest any extension link here. I want to check programmatically.







      magento-1.9 captcha






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 16 '18 at 5:58







      Rohan Hapani

















      asked May 16 '18 at 5:46









      Rohan HapaniRohan Hapani

      1




      1





      bumped to the homepage by Community 13 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 13 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          2 Answers
          2






          active

          oldest

          votes


















          0














          I think you have to try with using google recaptcha div class instead of id in jquery to getting google recaptcha response. I have tried below code and it's working for me:-



          <div class="news-captcha">
          <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
          </div>


          JS CODE:-



          var googleResponse = jQuery('.news-captcha .g-recaptcha-response').val();
          if (googleResponse!= ""){
          return true;
          }
          else {
          return false;
          }


          After getting response you have to pass this response in input "hidden" field. In the form submit action controller function you can use this hidden field post value and check there that recaptcha response getting or empty response.






          share|improve this answer

































            0














            Please Try with below code :





            <form>
            <script src='https://www.google.com/recaptcha/api.js'></script>
            <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
            <input type="button" name="submit" value="Sub" onclick="checkcaptcha();">
            <div id="captcha-error"><span></span></div>

            </form>

            <script type="text/javascript">
            function checkcaptcha() {
            var googleResponse = jQuery('.g-recaptcha-response').val();
            if(googleResponse !='') {
            jQuery("#captcha-error span").text("Your text here");
            jQuery('.captcha-error').css('display','block');
            return false;
            }

            }
            </script>





            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "479"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f226169%2fmagento-1-9-validate-the-google-recaptcha-in-custom-popup%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              I think you have to try with using google recaptcha div class instead of id in jquery to getting google recaptcha response. I have tried below code and it's working for me:-



              <div class="news-captcha">
              <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
              </div>


              JS CODE:-



              var googleResponse = jQuery('.news-captcha .g-recaptcha-response').val();
              if (googleResponse!= ""){
              return true;
              }
              else {
              return false;
              }


              After getting response you have to pass this response in input "hidden" field. In the form submit action controller function you can use this hidden field post value and check there that recaptcha response getting or empty response.






              share|improve this answer






























                0














                I think you have to try with using google recaptcha div class instead of id in jquery to getting google recaptcha response. I have tried below code and it's working for me:-



                <div class="news-captcha">
                <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
                </div>


                JS CODE:-



                var googleResponse = jQuery('.news-captcha .g-recaptcha-response').val();
                if (googleResponse!= ""){
                return true;
                }
                else {
                return false;
                }


                After getting response you have to pass this response in input "hidden" field. In the form submit action controller function you can use this hidden field post value and check there that recaptcha response getting or empty response.






                share|improve this answer




























                  0












                  0








                  0







                  I think you have to try with using google recaptcha div class instead of id in jquery to getting google recaptcha response. I have tried below code and it's working for me:-



                  <div class="news-captcha">
                  <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
                  </div>


                  JS CODE:-



                  var googleResponse = jQuery('.news-captcha .g-recaptcha-response').val();
                  if (googleResponse!= ""){
                  return true;
                  }
                  else {
                  return false;
                  }


                  After getting response you have to pass this response in input "hidden" field. In the form submit action controller function you can use this hidden field post value and check there that recaptcha response getting or empty response.






                  share|improve this answer















                  I think you have to try with using google recaptcha div class instead of id in jquery to getting google recaptcha response. I have tried below code and it's working for me:-



                  <div class="news-captcha">
                  <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
                  </div>


                  JS CODE:-



                  var googleResponse = jQuery('.news-captcha .g-recaptcha-response').val();
                  if (googleResponse!= ""){
                  return true;
                  }
                  else {
                  return false;
                  }


                  After getting response you have to pass this response in input "hidden" field. In the form submit action controller function you can use this hidden field post value and check there that recaptcha response getting or empty response.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 16 '18 at 9:43

























                  answered May 16 '18 at 9:22









                  RajRaj

                  311112




                  311112

























                      0














                      Please Try with below code :





                      <form>
                      <script src='https://www.google.com/recaptcha/api.js'></script>
                      <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
                      <input type="button" name="submit" value="Sub" onclick="checkcaptcha();">
                      <div id="captcha-error"><span></span></div>

                      </form>

                      <script type="text/javascript">
                      function checkcaptcha() {
                      var googleResponse = jQuery('.g-recaptcha-response').val();
                      if(googleResponse !='') {
                      jQuery("#captcha-error span").text("Your text here");
                      jQuery('.captcha-error').css('display','block');
                      return false;
                      }

                      }
                      </script>





                      share|improve this answer




























                        0














                        Please Try with below code :





                        <form>
                        <script src='https://www.google.com/recaptcha/api.js'></script>
                        <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
                        <input type="button" name="submit" value="Sub" onclick="checkcaptcha();">
                        <div id="captcha-error"><span></span></div>

                        </form>

                        <script type="text/javascript">
                        function checkcaptcha() {
                        var googleResponse = jQuery('.g-recaptcha-response').val();
                        if(googleResponse !='') {
                        jQuery("#captcha-error span").text("Your text here");
                        jQuery('.captcha-error').css('display','block');
                        return false;
                        }

                        }
                        </script>





                        share|improve this answer


























                          0












                          0








                          0







                          Please Try with below code :





                          <form>
                          <script src='https://www.google.com/recaptcha/api.js'></script>
                          <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
                          <input type="button" name="submit" value="Sub" onclick="checkcaptcha();">
                          <div id="captcha-error"><span></span></div>

                          </form>

                          <script type="text/javascript">
                          function checkcaptcha() {
                          var googleResponse = jQuery('.g-recaptcha-response').val();
                          if(googleResponse !='') {
                          jQuery("#captcha-error span").text("Your text here");
                          jQuery('.captcha-error').css('display','block');
                          return false;
                          }

                          }
                          </script>





                          share|improve this answer













                          Please Try with below code :





                          <form>
                          <script src='https://www.google.com/recaptcha/api.js'></script>
                          <div class="g-recaptcha" data-sitekey="XXXXXXXXXX"></div>
                          <input type="button" name="submit" value="Sub" onclick="checkcaptcha();">
                          <div id="captcha-error"><span></span></div>

                          </form>

                          <script type="text/javascript">
                          function checkcaptcha() {
                          var googleResponse = jQuery('.g-recaptcha-response').val();
                          if(googleResponse !='') {
                          jQuery("#captcha-error span").text("Your text here");
                          jQuery('.captcha-error').css('display','block');
                          return false;
                          }

                          }
                          </script>






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered May 16 '18 at 13:28









                          Ravi OzaRavi Oza

                          1388




                          1388






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Magento Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f226169%2fmagento-1-9-validate-the-google-recaptcha-in-custom-popup%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              What other Star Trek series did the main TNG cast show up in?

                              Berlina muro

                              Berlina aerponto