Overview of building custom fields for Gravity Forms

Gravity Forms is a great way to build all sorts of forms in WordPress. It can be so simple that non-programmers can easily build their own basic forms. It’s also incredibly flexible so programmers can extend it in myriad ways, even by adding some complex custom fields of their own. But as usual, there’s a trade-off — ease of use for non-programmers means lots of hoops to jump for programmers. Here’s an overview of how I built some fairly complex compound fields for a custom application using Gravity Forms.

First off, I have to give props to Travis Smith for his tutorial for building custom fields in Gravity Forms. This tutorial gave me an incredible kick-start on the path to building custom fields. If you want to know how to build custom fields for Gravity Forms, go read Travis’ article now! Go on, I’ll wait.

You’re back? Good. Now, I’m not going to get into details, since you’ve already Travis’ article and know the basics. What I’m going to do here is list the hooks I used, and why. What I built was a couple of pretty complex fields that needed to support multiple front-end form inputs per field, nicely formatted listings and detail views at the back end, CSV exports, and calculations. If I explained it all in detail, it’d take me all night. Each hook is linked to the Gravity Forms documentation, so you can get more detail there.

So, to the hooks.

Yes, that’s quite a few hooks. I reckon that there’s easily a good 1,000 lines of PHP and JavaScript supporting just one of my compound fields (maybe more, maybe less with some reuse of that code for a second custom field). But the custom fields make a huge difference to the usability and performance of the forms, so job is done to good effect.

  • Brandon

    Nice article! Do you have any docs or code that will easily allow you to reference the tables and or event names/attendees in the event manager?

    That would be very helpful.

    • G’day Brandon, are you talking about Gravity Forms or Events Manager, or…

      • Brandon

        Forgot to note that, got a little eager.

        I was wondering if you have anything in regards to pulling event manager data into gravity forms.

        ie. Dropdown field that will list – event names, locations, attendees etc.

        • Interesting, that could be a nice little plugin to write. The big complex thing I wrote about above is much bigger than this — you could manage that by following Travis Smith’s tutorial, just replace the checkbox with a dropdown list. You can get lists of events and locations easily from the Events Manager objects — just look in the classes EM_Events (em-events.php) and EM_Locations (em-locations.php). Why don’t you have a try?

  • Bill

    Could you share your code? I find it helps to look at other people’s code!

    • G’day Bill,

      I can’t really share the code for what I described above, because it belongs to the client who commissioned it. However, I had previously done a custom field for recurring payments on my Gravity Forms eWAY plugin, so you could download that and read the source code for it. The custom field is mostly wrapped up in its own PHP class so it’s fairly easy to find the code specific to that field.

      It doesn’t implement all of the things I discuss above, and I learned some better ways to handle things in the more recent plugin, but you should be able to get a clear idea of how it all works.


  • WordPress is GPL, therefore the code itself is GPL.