Introduction
The GFAPI::get_fields_by_type()
and GFAPI::get_field()
methods are used to get form fields.
Getting fields of specific types
The GFAPI::get_fields_by_type()
method is used to get all fields that match the specified type(s) from a specific form.
Source Code
public static function get_fields_by_type( $form, $types, $use_input_type = false ) {}
This method is located in /includes/api.php.
Parameters
Param | Type | Description |
---|---|---|
$form | array | An associative array containing the form settings, fields, notifications, confirmations, and other properties (e.g. add-on settings). See Form Object. |
$types | array|string | The field types to get. Using a string for a single type or an array to get multiple types. |
$use_input_type | boolean | Optional. Indicates if the field inputType property should be checked.Default: false |
Returns
An array of Field Objects of matching type(s).
Usage Example
$result = GFAPI::get_fields_by_type( $form, array( 'checkbox' ), true );
Getting a specific field
The GFAPI::get_field()
method is used to get a specific field from a specific form.
Since
The GFAPI::get_field()
method was added in version 2.3.
Source Code
public static function get_field( $form_or_id, $field_id ) {}
This method is located in /includes/api.php.
Parameters
Param | Type | Description |
---|---|---|
$form_or_id | integer|array | The form ID or Object. |
$field_id | integer | The field or input ID. |
Returns
A Field Object or boolean (false
) if the field can’t be found.
Usage Example
// Passing the form object with the field id.
$field_one = GFAPI::get_field( $form, 1 );
// Passing the form id with the field id.
$field_one = GFAPI::get_field( 2, 1 );
// Passing the form id with the input id.
$field_one = GFAPI::get_field( 2, '1.3' );