Questions? Email Me
Dynamically Populate Price Field in Gravity Forms
Dynamically Populate a Gravity Forms Dropdown with ACF Field Data
Without a single line of code!
- Grab a copy of the Gravity Forms Dynamic Population Pro plugin
- Add a dropdown field for people to choose their desired post
- Add a dropdown field to your form with the ACF field name
- Add a dropdown field to the form that selects the data from the WordPress postmeta table, with the choices filtered by the post ID (step 2) and meta key (ACF field name from step 3)
Questions? Email Me
Dynamically Populate a Gravity Forms Dropdown With Custom Post Type
Without a single line of code!
- Grab a copy of the Dynamic Population Pro plugin
- Add a dropdown field to your form with the name of the custom post type and pre-select the option
- Add another dropdown field to hold your custom post type titles and set your dynamic choice options to filter the the WordPress posts table to only get the posts that match the post type in your dropdown from step 2
Questions? Email Me
Change Feed Priority When Using the Gravity Forms Add-On Framework
The Gravity Forms Add-On Framework is a great time-saver for developing your custom Gravity Forms functionality. In chatting with another developer, the question of adjusting the feed priority came up.
How can you control the order in which feeds are processed?
In this situation, they needed to save data in one feed and then use that data in another feed, so it was important that the feeds fire in a particular order.
If you’re using the Add-On Framework, you likely understand object-oriented programming concepts β especially inheritance β so this isn’t a difficult task at all. There are a few ways to handle this, but here’s a simple way:
public function init() { GFAddOn::init(); add_filter( 'gform_entry_post_save', array( $this, 'maybe_process_feed' ), 9, 2 ); }
Simply override the function that adds the filter to process the feed β GFFeedAddOn
init
β and add the filter with your desired priority.
In this example, we’re setting this particular Add-On’s feed to process *before* the ones with the default priority. It doesn’t affect the priority of any other Add-Ons.
Questions? Email Me
Make Gravity Forms Hidden Field a Certain Type
Sometimes you need to have some data on your form, but it needs to be hidden. Gravity Forms has a hidden field type β perfect! Or is it?
What if you need the field to be a certain type? Like a product field, or date field, or any other Gravity Forms field? A Gravity Forms hidden field is a basic text field β it doesn’t provide any formatting for a specific type of data like the other Gravity Forms fields. So how can you make a Gravity Forms hidden field be a certain type?
Well, you can’t. But, you can simply use whatever field type you want and then hide it with CSS. Every time I mention that to a client, they look at me, I look back at them, they look back at me…ok, you get it. I patiently allow them to go through the stages of their “why didn’t I think of that” moment π
And, Gravity Forms does you aΒ big favor when it comes to common CSS adjustments β they provide ready-made classes that you can use on the Appearance tab of any Gravity Forms field, in the ‘Custom CSS Class’ box. So, to hide a field, simply use the gf_invisible class.
Hope that helped!
Questions? Email Me
Prevent a Field from Saving to the Gravity Forms Entry
For whatever reason, you may want to redact a Gravity Forms field β a fancy way of saying that you don’t want the data that your user enters in that field to be saved to the Gravity Forms entry that gets created when the form is submitted. This is particularly helpful when you have sensitive information that you need to collect and process, but you do *not* want to store it in your database. For example, you need the user to enter a billing address to send it to your payment processor, but afterwards you don’t want to save that information.
The Gravity Forms Utility plugin adds an option to each form field, allowing you to check a box to redact that field’s data, making sure it never gets saved to the entry. Note that the information is forever unrecoverable β so only use it if you mean it!
Questions? Email Me
Setup Multiple Payment Options on One Gravity Form
How can I give users the choice of paying with PayPal or [another payment processor]?
This is a common question I get with the Gravity Forms + Stripe Add-On, but it applies to any other payment processor.
To accomplish this, you need one field to hold all of your possible choices and then you can use that field in your conditional logic. Here’s how we do it with Gravity Forms + Stripe:
- On your form, create a radio button field to allow your user to choose whether they will be paying with PayPal or Stripe (substitute your payment processor for Stripe if you’re using someone else)
- Create your product field(s)
- Add your credit card field and enable conditional logic on this field, only showing the field if the person chose Stripe. Skip this step if your PayPal version accepts credit cards via the Gravity Forms credit card field, and/or if your other payment processor does not accept credit card payments (e.g. if you were using PayPal and Dwolla).
- Create a Stripe rule and enable the Stripe condition on the rule so that itβs only triggered when the user selects the Stripe payment option
- Create a PayPal feed, and enable the PayPal condition on the feed so that itβs only triggered when the user selects PayPal
But what if I need recurring payments, too?
You’ll just expand your options. Instead of having only two options: Stripe and PayPal. You’d have four options:
- One-time payment (Credit Card)
- One-time payment (PayPal)
- Recurring payment (Credit Card)
- Recurring payment (PayPal)
And you’d be able to use those options on both your credit card field (if necessary) and in your one-time payment and recurring payment feeds (most Gravity Forms payment add-ons require separate feeds for one-time payments and subscription payments).
The key is that all of your options have to be in one field β you can’t split the options into multiple fields.
And here’s an example form you can download, unzip, and import into your site to see how it works right in your Gravity Forms form editor:
gravityplus-multiple-payment-options-example-form.xml
Questions? Email Me
Setup Gravity Forms Conditional Confirmation or Notification Messages Based on Submitted Values
Have you ever wanted to have your confirmation or notification messages say different things depending on the submitted values?
Take the form below as an example:
Based on which option the user chooses, I’d like to display a different message when they submit the form, and the Gravity Forms conditional shortcode is just what I’m looking for.
The Gravity Forms conditional shortcode allows you to show different content depending on the values of the submitted form fields. In my example, I have a different message for each option the user can choose:
So here’s how to use them:
[gravityforms action="conditional"
Start with the shortcode name and the action, which is always “conditional”merge_tag=""
Add the form field that has the value you want to check. You can insert the merge tag for the form field using the merge tag dropdown.condition=""
Indicate the type of comparison you will be doing. The possible conditions are is, isnot, greater_than, less_than, contains, starts_with, ends_with.value=""
Enter the value that you want to compare the submitted value with.]
Close the opening shortcode.- After you close the opening shortcode, enter your desired content for this condition
[/gravityforms]
Finally, enter the closing shortcode
[gravityforms action="conditional" merge_tag="{Field:1}" condition="is" value="desired value"]Show this content if the field is equal to the field value I specified earlier[/gravityforms]
You can add as many conditional shortcodes as needed in your message.
Questions? Email Me
Programmatically Trigger Gravity Forms Notification
Until it makes its way to the new Gravity Forms API, you can programmatically send a specific Gravity Forms notification using the GFCommon::send_notification
function which receives the notification ID, the form object, and the lead object.
If you need to send multiple notifications, you can use GFCommon::send_notifications
which receives an array of IDs.
Here’s how I use send all of the notifications for a specific event that occurs:
<?php | |
function send_notification ( $event, $form, $lead ) { | |
$notifications = GFCommon::get_notifications_to_send( $event, $form, $lead ); | |
$notifications_to_send = array(); | |
//running through filters that disable form submission notifications | |
foreach ( $notifications as $notification ) { | |
if ( apply_filters( "gform_disable_notification_{$form['id']}", apply_filters( 'gform_disable_notification', false, $notification, $form, $lead ), $notification, $form, $lead ) ) { | |
//skip notifications if it has been disabled by a hook | |
continue; | |
} | |
$notifications_to_send[] = $notification['id']; | |
} | |
GFCommon::send_notifications( $notifications_to_send, $form, $lead, true, $event ); | |
} | |
?> |
Questions? Email Me