Beta testing of the new Gravity Forms integration with Pods is going on NOW!
This code has evolved as it’s been used on a number of my projects since I started using Gravity Forms when it first came out back in 2009. I’ve refactored it a bit, and it’s now available for devs to geek out with their PHP out.
It doesn’t have a UI yet, so it’s really meant to be tested on a manual PHP integration at the moment.
This component will be baked into Pods 2.0 itself, but the code as it is right now was built to work with Pods 1.12+
Mapping a GF entry to a new Pod item
To map a GF entry, hook into the gform_post_submission action for the form you want to integrate with. I usually hook into the gform_post_submission action itself and handle all my forms within a few if/else statements. Once in the function that runs during that action, you just map your $entry array to the Pods_GravityForms::map function.
Pods_GravityForms::map( $entry, $pod_name, $mapping );
$mapping is a key=>value array of fields (key is the GF field ID, value is the pod column name).
In $mapping, you can provide an array for the value, which can contain many other options. Some examples of these would be ‘field’ (the name of the Pod field to save into), ‘bool’ (see below for BOOLEAN fields), ‘default’ (the value to set if no value is given by the form), and ‘bypass_value_set’ (don’t get the value from the GF field value, always use the ‘default’ for value).
For PICK fields, Pods will check to see if the value passed by GF is numeric, if not, it will look up your items by name and try to find the best match. I usually setup my corresponding fields in GF to send back the value as the Pod item ID I want to relate to. You can optionally create your own dynamic field options with the ‘gform_pre_render’ action in GF, hooking into the field’s ‘choices’ array, set the text and value as you need.
For BOOLEAN fields, Gravity Forms sends back Yes / No, or other text depending on how you’ve labeled that field. In those cases, set your map field array value of ‘bool’ to the ‘Yes’ value you want to be triggered by.
Creating a Faux $entry array during validation / pre-processing
Since Gravity Forms doesn’t give you a standard data array both in pre AND post, with this code you can also build a faux $entry array in your GF validation / pre-processing. This also makes it possible to map a GF entry to a Pod before the entry has actually been created in GF.
$entry = Pods_GravityForms::setup_entry( $gf_validation );
That’s the simple version of it, there’s a lot more complexity built in that I’ll try to get some more examples posted here asap.
A few extra methods for most common needs
In most of my form integrations with GF, I’ve had a need for a few methods that I threw in here for your enjoyment as well!
Auto delete the entry GF creates, which runs after post-processing:
Pods_GravityForms::auto_delete( $form_id );
Auto login a user from GF User Registration form:
Pods_GravityForms::auto_login();
Set a select field’s values to pull from a Pod instead of being static/hard coded:
Pods_GravityForms::dynamic_select( $form_id, $field_id, $pod_name, $label_column_name, $params );
Get the Pods + Gravity Forms integration code at GitHub
https://github.com/pods-framework/pods/blob/2.0/components/GravityForms.php