Search code examples
angularwordpressapirecaptchagravity-forms-plugin

GravityForms - Post form with Google Recaptcha via GF API (Backend)


How to submit a Gravity Form via GF API that contains Google Recap v2 Checkbox?

I have an api /post_signup_form that would get my signup (id = 2) and then post the submission. Right now, the form has 2 fields, email and recaptcha field.

From the Gravity Form Docs, below is what I have to post my form via GFAPI. The recaptcha string comes from an angular form (using ng-recaptcha) that would submit it to my website's custom api endpoint.

$input_values = [
  'input_1' => 'test@email.com'
  'input_2' => 'really_long_recap_string'
];

$result = GFAPI::submit_form( 2, $input_values );

Right now, I'm just sending the token after completing the checkbox challenge in the angular app, but, it always returns RECAPTCHA was invalid message. How am I suppose to post a gravity form with GFAPI that contains google recaptcha?

Would I need to verify that token (https://www.google.com/recaptcha/api/siteverify) before submitting the form?


Solution

  • Instead of integrating Google Recaptcha with the Angular Application, add conditional logic to the gravity forms recaptcha field to not show when it's the angular application.

    Because the conditional logic, GFAPI submit form no longer requires the captcha field.