Custom field IDs for Gravity Forms

If you haven’t had the chance to work with it before, Gravity Forms is pretty fantastic. I was first turned onto it a few years ago while I was at Buckeye Interactive, where it was a mainstay across most of our client sites. Besides presenting an easy-to-manage interface for building forms, the plugin also makes good use of the WordPress Plugin API (thus making my life way easier) and has a vibrant ecosystem of official and unofficial add-ons.

One area where Gravity Forms could stand to improve, however, is making it easier to identify fields. Let’s say, for example, we have a form where we’re collecting a name and an email address; outside of assuming that the regular text field is the name and the input[type="email"] is the email address, Gravity Forms doesn’t really have a straight-forward way to identify fields when you’re doing extra work with submissions (like sending them to a newsletter or a CRM system).

In my new role as Director of Technology at Growella, one of the first things I needed to figure out was how we could reliably map Gravity Forms submissions into third-party tools.

Assigning custom IDs to fields

Fortunately, Gravity Forms lets us add custom properties to our fields; knowing this, we can easily add a “Field ID” input, which lets us reference a field by this ID:

This function will generate the Field ID input markup on the gform_field_advanced_settings action, calling Gravity Forms’ setFieldProperty() function whenever the input changes.

Next, we need to tell Gravity Forms that fieldID is a valid property:

This will also pre-populate the input’s value with a field ID, if one has previously been saved.

A Gravity Forms field with a custom "Field ID" input

That’s it! With these two functions, we’re able to assign custom field IDs, removing a lot of the headache of mapping to third-party services.

Mapping Gravity Forms fields to third-party services

Having the custom field IDs is great, but the icing on the cake is being able to easily get any fields with custom IDs to send to your third-party services. Thanks to your friends at Growella, now you can:

In almost any Gravity Forms callback (for example, gform_after_submission), we receive two arrays: $entry and $form. By passing these directly to growella_get_mapped_fields(), we can quickly retrieve non-empty values for fields we’ve assigned IDs to. For example:

Now, go forth and integrate Gravity Forms with :allthethings:!

17 comments on "Custom field IDs for Gravity Forms"

  1. Andy 2 years ago

    Great post, thanks for sharing your code; I was having the very same problems pulling out and sharing data collected from forms and this code looks like a great starting point!

    Many thanks!

    • studio4 2 years ago

      Just in case anyone else is interested in this if you want to add the fieldID to the front-end form as a class you can use the gform_field_css_class hook:

      * Show mapped field ID in front-end forms for CSS and JS manipulation
      * @param [type] $classes existing classes string
      * @param [type] $field field object
      * @param [type] $form form object
      * @return [type] new classes string
      function growella_gform_custom_class( $classes, $field, $form ) {

      if ( $field->fieldID ) {
      $classes .= ‘ ‘.$field->fieldID;
      return $classes;
      add_filter( ‘gform_field_css_class’, ‘growella_gform_custom_class’, 10, 3 );

  2. Mike 2 years ago

    Perfect – just what I needed! Cheers :)

  3. Jonathan 2 years ago

    are we placing this in the theme functions.php file or a specific php file in the gravity forms plugin folder?

    • Steve 2 years ago

      This would be in your theme’s functions.php file — you should never have to modify the code within wp-content/plugins/gravity-forms, as that would be wiped out with the next update.

      • Jonathan 2 years ago

        Thanks Steve. I had some cache issues on my end and wasn’t seeing the update. i’m all set though now.

  4. lukecav 1 year ago

    Awesome share, thanks for this.

  5. Cristian W. 1 year ago

    I just wanted to say thank you. This solved my problem.

  6. Carlos Gouveia 10 months ago


    I need to export with this field id and not the field name. How can I do that? Cheers

  7. Folkert 10 months ago

    Thanks for this:) Implemented the first two script. However, the newly created field to change the ‘fieldid’ of a field adds a class to the field instead of changing the fieldid. Anybody some thoughts on this?

  8. joelambert100 8 months ago

    I’m having some trouble getting this working now too, not sure if Gravity forms has updated something which breaks this, but it no longer appears to output the custom ID to the front end anymore.

  9. adrian 7 months ago

    Seeing the same thing here – not seeing the new custom field ID on the front end.

  10. sher 7 months ago

    I’m getting an error for line 11

  11. djbourque 5 months ago

    I have added everything to the function.php and see the field id field in gravity forms however it does not change the actual ID in the form.

    Any thoughts

  12. casasalpinas 4 months ago

    I used this but I’m not seeing the results in the frontend. Maybe gravityforms changed the code?

  13. Richard 1 month ago

    Do you have a step by step tutorial on implementing this? Much appreciated.

  14. Judy Wong 2 days ago

    Thanks! saved my life :)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.