Dynamically Populate a Gravity Forms Dropdown with ACF Field Data

Without a single line of code!

  1. Grab a copy of the Gravity Forms Dynamic Population Pro plugin

  2. Either add a hidden field to your form with the post ID you want to grab the ACF data from, or add a dropdown field for people to choose their desired post

  3. Add a hidden field to your form with the ACF field name

    Gravity Forms dynamically populate dropdown with ACF field data

    Gravity Forms dynamically populate dropdown with ACF field data post meta

  4. 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)

    Gravity Forms dynamically populate dropdown with ACF field data post meta



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! gravity-forms-dont-save-field-data-to-database



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:

  1. 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)
    Gravity Forms Multiple Payment Options Radio Button Field
  2. Create your product field(s)
  3. 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).
    Gravity Forms Credit Card Field Condition
  4. 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
    Gravity Forms Stripe Payment Feed Conditional Logic
  5. 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:

  1. One-time payment (Credit Card)
  2. One-time payment (PayPal)
  3. Recurring payment (Credit Card)
  4. 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:
Gravity Forms Form Editor Radio Button Option Field

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:
Gravity Forms conditional confirmation message

So here’s how to use them:

  1. [gravityforms action="conditional"
    Start with the shortcode name and the action, which is always “conditional”
  2. 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. Gravity Forms Merge Tag Dropdown
  3. 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.
  4. value=""
    Enter the value that you want to compare the submitted value with.
  5. ]
    Close the opening shortcode.
  6. After you close the opening shortcode, enter your desired content for this condition
  7. [/gravityforms]
    Finally, enter the closing shortcode
Putting it all together, we have:
[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

Customize the Gravity Forms CSS

Customizing the Gravity Forms CSS is easily one of the most painful aspects of working with Gravity Forms. Over time, I’ve collected several resources which I’ll share with you here.

Plugins

I’ve recommended this one to a few people, and they’ve enjoyed it:
Gravity Forms Styler

This is an interesting one that integrates with many different WordPress themes and plugins:
CSS Hero (demo)

This one is by WordPress support company Maintainn:
Gravity Forms Custom Styles

Tutorials

Gravity Forms + Bootstrap: Helpful function for adding Bootstrap classes to Gravity Forms fields

Styling Gravity Forms with Bootstrap

A collection of tutorials on how to format and style Gravity Forms



Note: Some of these are affiliate links and I may earn a commission if you purchase through one of them. I’m not writing here to make money so feel free not to use — they’re available as an easy way for you to say thank you if you appreciate me pointing you to something that ends up being useful for you.



Questions? Email Me

Prevent Gravity Forms Entry Creation

While you can’t currently prevent Gravity Forms from creating an entry (and you may not want to just in case it breaks something else that needs the entry information in the course of processing the form submission), you *can* delete the entry after the form has finished submitting using the gform_after_submission_{$form['id']} action hook and the Gravity Forms API.

So, if your form ID is 10, your code would be:

add_action( 'gform_after_submission_10', 'mysite_gform_after_submission_10', 10, 2 ); function mysite_gform_after_submission_10 ( $entry, $form ) {
GFAPI::delete_entry( $entry['id'] );
}

If you don’t want to worry about code, and want to be able to just enable this on any form you’d like by checking a box on the Form Settings page, use the Gravity Forms Utility plugin.

Disclaimer: You’ll want to check the other Gravity Forms integrations you’re using (if any), and make sure they don’t depend on a Gravity Forms entry after the form has been submitted. For example, the Gravity Forms + Stripe extension adds payment information to the entry and looks for it later. If the entry isn’t there, some of the Stripe functionality will be unavailable.



Questions? Email Me