Getting Forms with the GFAPI

Introduction

The following GFAPI methods can be used to get and check if forms exist.

Checking if a specific form exists

The GFAPI::form_id_exists() method is used to check if a form exists with a specific ID.

Source Code

public static function form_id_exists( $form_id ) {}

This method is located in /includes/api.php.

Parameters

ParamTypeDescription
$form_idintegerThe ID of the form to check.

Returns

Boolean. True if the form exists. False if the form doesn’t exist.

Usage Example

$result = GFAPI::form_id_exists( $form_id );

Getting a specific form

The GFAPI::get_form() method is used to get a form by its ID.

Source Code

public static function get_form( $form_id ) {}

This method is located in /includes/api.php.

Parameters

ParamTypeDescription
$form_idintegerThe ID of the form to retrieve.

Returns

An array (Form Object), if the form exists. Boolean, false, if an error occurs.

Usage Example

$result = GFAPI::get_form( $form_id );

Getting multiple forms

The GFAPI::get_forms() method is used to get all forms that match the given arguments.

Source Code

public static function get_forms( $active = true, $trash = false, $sort_column = 'id', $sort_dir = 'ASC' ) {}

This method is located in /includes/api.php.

Parameters

ParamTypeDescription
$activeboolean|nulltrue to only get active forms.
false to only get inactive forms.
null to ignore the form is_active property (since v2.5.8).
Defaults to true.
$trashboolean|nulltrue to only get trashed forms.
false to only get forms not in the trash.
null to ignore the form is_trash property (since v2.5.8).
Defaults to false.
$sort_columnstringThe column to sort the results by.
Accepted values: id, title, date_created, is_active, and is_trash.
Defaults to id.
Since v2.5.
$sort_dirstringThe direction to sort the results.
Accepted values: ASC and DESC.
Defaults to ASC.
Since v2.5.

Returns

An array of forms (Form Object) that match the given arguments or an empty array.

Usage Example

$result = GFAPI::get_forms();