In this tutorial we’ll cover something quite useful – what Gravity Forms hook should we use to send our collected values to the external form with redirect.

Say we have several Gravity Forms forms, each one of them having different set of fields. We want to collect the submitted values and redirect the user with the prefilled values, using GET parameter. Our API will then handle these form and either submit the form, or ask the user to complete the submission.

Redirect Prerequisties

If the API is on an external domain we have to whitelist it first, let’s use the following hook:

If we haven’t used it, then we’d simply be redirected to the wp-admin part of the site. This is quite good practice actually, as we are in the control of the redirect. This both makes sure that we avoid accidental redirects and send the user where intended. In case the redirect was variable based and our site hijacked – say someone wanted to collect our leads and would spoof the URL, the submittees would not hit the wrong site. This also makes sure that noone accidentally submits a wrong form, after hitting a similar site which sole purpose is to steal the leads.

Gravity Hooks

For the purpose of this tutorial I assume that we want to have the whole data collected and a full Gravity Forms entry created.

Knowing that we need to hook into gravity forms confirmation hook:

This hook will collect the lead data and construct the final URL using useful WordPress methods and hooks: add_query_arg ,  allowed_redirect_hosts, wp_safe_redirect.