Yet another programmer blogging about code

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.

Update: this post was written before the Gravity Forms add-on framework was a thing. Everything is much simpler now using that framework, and its field framework, so please refer to that now. This post is preserved for historical amusement only!

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.