How To Check if a Gravity Form Exists

Recently we had a project where we had to see if a Gravity Form existed before outputting anything. The reason we had this issue was because the plugin would be on a bunch of themes, each with different form numbers. As such, if the form didn’t exist, we’d have an ugly “We Couldn’t Find The Form” text.

Gravity Forms (from our experience) didn’t have a check to see if a form with ID $id existed, so we had to write a function to find this. The easiest way we found was interacting with the database directly.

The form is recorded in the rg_form table, so we’re simply going to use WordPress’ $wpdb class to run an SQL query. If we get a value back that’s bigger than 0, then we know that the from exists.

Code To Check if a Gravity Forms Exists

To use this code, simply call this within an if statement:-

Let me know if you find this useful!

Similar Posts