Gravity Forms Tip: Clean Confirmation Redirects

Posted in Gravity Forms Tip on May 3rd, 2010

If you’re familiar with Gravity Forms you might know that when using the confirmation redirect feature either to a page or a URL, you’ll see a very quick flicker as the form posts back to itself and then redirects you to the specified page or URL. Not a huge deal… but once you notice it, it’s hard to ignore. If you’ve never noticed it before… well, sorry to Shallow Hal* you, but we can make this fat chick beautiful with a surprisingly simple bit of code:

add_filter("gform_post_submission", "hide_form", 10, 2);
function hide_form($entry, $form) {
    if($form["confirmation"]["type"] != "message")
        echo '';
}

So what are we doing here? Not much. We’re just using one of Gravity Forms built in filters gform_post_submission to call a custom function that we create below called hide_form. Whenever I finally understand what those last two parameters do, I’ll tell you too.

So the filter passes two parameters to the function which are $entry and $form. The $entry variable is an array of all the values entered into the form and the $form variable is an array of juicy information about the form itself. For our purpose, we only need the $form array. This array contains a property called “confirmation” which contains a property called “type” which contains a single value which will either be “message”, “page”, or “url”.

Two of these values (“page” and “url”) mean that the form is going to be redirecting to either a page or you guessed it! A URL! If the form confirmation type is set to “message”, however, the form will not be redirecting and so we want to make sure that whatever we’re going to do for the redirection confirmation types, we do not want to do for the non-redirection confirmation type. This is accomplished with a simple conditional that in reads “if the confirmation type is not ‘message’ then run the following code”.

That brings us to the handy dandy style declaration that hides the body of the page so the redirect can be processed without any visual interference. That’s right. No annoying flicker when the form page begins to load and is then redirected to the actual confirmation page. Any questions?

PS – Sorry for the lack of a comments section. This site was originally designed as a strictly portfolio site and I’ve been adding to it since. Drop me a line on my contact form if you’ve got something to share. :)

* If you haven’t seen the movie, ignore this reference.