1

I have used this code from google recaptcha, but the submit didn't work (after google captcha nothing happen), the form is not submitted, maybe because i have added my own action for the salesforce ?

    <html>
    <head>
    <script>
  var onSubmit = function(token) {
      console.log('success!');
    };

        var onloadCallback = function() {
          grecaptcha.render('submit', {
            'sitekey' : 'your_site_key',
            'callback' : onSubmit
          });
        };
    </script>
  </head>
  <body>
    <form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" thod="POST">
      <input id='submit' type="submit" value="Submit">
    </form>
    <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
        async defer>
    </script>

      </body>
</html>

i have also used google recaptcha v3,

my form is submitted but in server side i receive an empty array.

Mohamed Masmoudi
  • 547
  • 1
  • 9
  • 23
  • 1
    I believe that 1. when you submit your form, it reloads the page. That's the default behaviour that needs to be prevented (event.preventDefault etc). Also 2. You wrote `thod` instead of `method.` – Jeremy Thille Sep 30 '20 at 12:54
  • Yes, i made a mistake writing method, i fix it but the form don't submit and reload the page, how can i fix that ? – Mohamed Masmoudi Sep 30 '20 at 16:42
  • By googling a little bit :) [Stop form refreshing page on submit](https://stackoverflow.com/questions/19454310/stop-form-refreshing-page-on-submit) – Jeremy Thille Sep 30 '20 at 17:39
  • This not the problem, my problem is that the form is not submitting at all, when click on submit button nothing happen, sometimes the google captcha appear that's all. – Mohamed Masmoudi Sep 30 '20 at 18:02
  • 1
    Hello @MohamedMasmoudi 2 questions: first in the `'sitekey' : 'your_site_key',` you used your recaptcha key right? second, do you get any errors in Console? – Mihail Minkov Oct 02 '20 at 15:36
  • 1
    It seems, I have a similar problem. The form submits fine without ReCAPTCHA. As soon as I call "render" on the submit button, the form does not get submit anymore, and the render's callback parameter does not get called neither. BTW, I've read that another guy fixed this by changing submit button's ID to something other than `submit` . I see that you have the same case, so maybe the solution for v2 was to change submit button's ID, in your case. – Jānis Elmeris Jun 21 '23 at 08:23
  • 1
    @JānisElmeris I have opted to recaptcha v3, it is easier to use and this solved my problem. – Mohamed Masmoudi Jun 21 '23 at 12:37

1 Answers1

0

To resolve my issue, i have upgrade it to the reCaptcha v3, it was a lot easier to integrate to my html code. Thanks everyone!

Mohamed Masmoudi
  • 547
  • 1
  • 9
  • 23