reCaptcha integration problem using React/Gatsby

Hi guys, how are you?

I created my HubSpot form, and due to having the “follow up” option on, the ReCaptcha is mandatory. When I go to my front end (I’m using React and Gatsby) and I install reCaptcha and register my site, everything loads but the form doesn’t submit. It always gives me a POST error (400). It almost seems that the ReCaptcha that the HubSpot form autogenerates and the one my page generates are not the same one, like if there are some issues with the integration because it simply doesn’t work :disappointed_face:
Does anyone have any idea of what I’m doing wrong, or how to make it work?
(just in case, if I go to my HubSpot form, delete the “follow up” and mandatory ReCaptcha, the form submits and works perfectly, but when I turn “follow up” again (and the mandatory ReCaptcha), it breaks. This leads me to think that the problem comes because the form is not recognizing the ReCaptcha value generated on my site.
Thanks for your time!
Nico

@miljkovicmisa , I feel like you might have some thoughts here :grinning_cat:

Hello @NicoElvino , :waving_hand:@dennisedson ,
thank you for writing, could you elaborate a bit more on why you need that second captcha on you site? As far as I’m concerned hubspot forms bring the captcha with them out of the box, so you don’t actually need to “install” it again on your site, maybe I’m missing something here, also some kind of log would be helpful, maybe the console log you get?
Cheers!

Hi @miljkovicmisa, thanks for your reply!

No worries, I will try to explain better :slightly_smiling_face:

1- I dont intend to use the “out of the box” HubSpot forms, but create custom ones and integrate them.

2- I built a website on React and Gatsby, deployed to gatsby cloud. In order to use Hubspot forms in there, Im creating my own forms and integrating HubSpot to them. I created 4 forms, all of them work perfectly, they submit, they send data and they dont have any issues.

For that, I use a code like this in my coponents, where I add my portal and form ID supplied from HutSpot:

const handleSubmit = (evt) => {

    evt.preventDefault();

    var xhr = new XMLHttpRequest();

    var url = 'https://api.hsforms.com/submissions/v3/integration/submit/5692042/f1905f2b-0c39-4a1f-8c96- 09c23514e92e'

    var data = {

        "fields": \[

            {

                "name": "firstname",

                "value": firstname

            },

            {

                "name": "email",

                "value": email

            }

        ],

Until here, everything works perfectly.

ISSUE:

3- When I go back to one of my working forms (is the same if I create a new one) and turn the “reCaptcha” on, then my forms spot working. (note: I dont even want to turn it on, but if I select the option “follow up”, then its mandatory to have it).

First thing: The automatic reCaptcha that is usually autogenerated in the “out of the box HubSpot form”, is not created in my custom component.

Second: if I add my own reCaptcha, now it displays and “works” (I mean, allows the user to interact and confirm that they are huamns), but the form doesnt submit, exactly the same as happened in the previous step. This takes me think that the problem is that the submit button is not storing the reCaptcha value, or expecting the one that should be “autogenerated” in the “out of the box form”, but that ll never happen as Im using my own forms.

Error:

POST https://api.hsforms.com/submissions/v3/integration/submit/5692042/f1905f2b-0c39-4a1f-8c96-09c23514e92e (400)

Probably its a simple solution, and hopefully Im simply missing something really basic that Im still now aware off!

Thanks for yout time!

Nico

Owww, okay, that explains it now, I thought that you are only doing the integration but you are also sending form data via API, that unfortunately is not possible, using captcha and sending form data programatically is not allowed. If you do a dump of the errors object you will see an entry that contains the FORM_HAS_RECAPTCHA_ENABLED errorType. Unfortunately there is no workaround except by using the hubspot embed code.
You may have missed it when reading the docs, but it is in this link waaaay down in the “errors” section of the table.
If my answer was helpful please mark it as a solution.