Target Gravity Forms by name, not ID

Gravity forms has one of the most comprehensive, and well documented sets of hooks for developers to use. Almost all hooks that pass a $form object can be added one of 2 ways, generically which will be called on all forms, or with the ID of a simple form appended, which will then run only on that form.

I’ve never liked having to use the IDs of a Gravity Form in code. It’s a join between something you can see, and something that is tucked away in the backend. If, for instance, a form gets exported, or replaced with a new, imported version, its ID will change, and the join will be broken, resulting in lost functionality.

There is a built in solution to this problem, using the static Gravity Forms function RGFormsModel::get_form_id():

This allows you to use names, not IDs in your code. Yes, a form could be renamed, but I’ll take that over an ID, any day.

Leave a Reply

Your email address will not be published. Required fields are marked *