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:
Forum One News
As a web developer, Matt assists with the design, development, testing, implementation, and maintenance of Forum One client web sites and solutions for online community building, information...





Comments
I would love to see Gravity
I would love to see Gravity Forms in Drupal!
Post new comment