Skip to Navigation

WordPress Plugin Integration: Gravity Forms

Printer-friendly version

Today we're going to explore Gravity Forms' form submission hook.

Gravity Forms is a WordPress forms plugin. It lets you visually create public-facing input forms, similar to Wufoo. You're able to build things like website surveys, event registrations, and (multi-step) payment processing forms.

The best part about Gravity Forms is that it doesn't try to do everything. It focuses on its core strengths (visual form creation), and has WordPress hooks to let other developers contribute additional functionality.

Hooking into form data

 
Let's look at the gform_post_submission hook. It fires after the form data has been saved successfully. There are many uses for this hook, including email confirmation, remote backup, etc.

When the gform_post_submission hook is triggered, call the gravity_forms_handler function. 10 is the priority (a lower number means earlier execution), and 2 means that the function should expect two parameters.

Gravity Forms data


Gravity Forms passes two parameters into our function: $entry and $form.

  • $entry contains the actual input values. See sample data
  • $form contains information about the input form itself, including field definitions. See sample data

As you can see, the fields and values are in separate arrays, so we'll need to figure out how to stitch them together.

Combining $entry and $form

 

Our goal is to have a single array, with each element containing the (A) field type, (B) field label, and (C) value.

Our results


Here's what we get after combining the two arrays:

Comments

I would love to see Gravity

I would love to see Gravity Forms in Drupal!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.