GF_Field
Class GF_Field
This class provides the base functionality for developers when creating new fields for Gravity Forms. It facilitates the following: Adding a button for the field to the form editor Defining the field title to be used in the form editor Defining which settings should be present when editing the field Registering the field as compatible with conditional logic Outputting field scripts to the form editor and front-end Defining the field appearance on the front-end, in the form editor and on the entry detail page Validating the field during submission Saving the entry value Defining how the entry value is displayed when merge tags are processed, on the entries list and entry detail pages Defining how the entry value should be formatted when used in csv exports and by framework based add-ons
Source: includes/fields/class-gf-field.php:24
Details
- Kind:
class - Namespace:
(global) - Extends:
stdClass - Implements:
ArrayAccess
Properties
| Property | Type | Description |
|---|---|---|
$is_payment | bool | Indicates the field is used to capture payments. |
$_supports_state_validation | bool | Indicates if this field supports state validation. |
$duplicatable | bool | Whether there can be more than one of this field type per form. |
$repeatable | bool | Whether the field can be used in a repeater. |
Methods
| Method | Description |
|---|---|
has_persistent_choices() | Whether the choice field has entries that persist after changing the field type. |
__get() | The getter method of the field property. |
set_context_property() | Set a context property for this field. |
set_input_validation_state() | Set the validation state for a single input within this field. |
get_default_properties() | Get default properties for a field. |
get_form_editor_field_title() | Returns the field title. |
get_form_editor_field_icon() | Returns the field's form editor icon. |
get_form_editor_field_type_icon() | Returns the form editor icon for the field type. |
get_form_editor_field_description() | Returns the field's form editor description. |
get_required_inputs_ids() | Defines the IDs of required inputs. |
get_form_editor_button() | Returns the field button properties for the form editor. The array contains two elements: |
get_form_editor_field_settings() | Returns the class names of the settings which should be available on the field in the form editor. |
is_conditional_logic_supported() | Override to indicate if this field type can be used when configuring conditional logic rules. |
get_form_editor_inline_script_on_page_render() | Returns the scripts to be included for this field type in the form editor. |
get_form_inline_script_on_page_render() | Returns the scripts to be included with the form init scripts on the front-end. |
get_field_input() | Returns the field inner markup. |
get_field_content() | Returns the field markup; including field label, description, validation, and the form editor admin buttons. |
get_field_label_tag() | Returns the HTML tag for the field label. |
get_field_sidebar_messages() | Checks if any messages should be displayed in the sidebar for this field, and returns the HTML markup for them. |
get_field_container() | Returns the HTML markup for the field's containing element. |
get_field_container_tag() | Returns the HTML tag for the field container. |
get_field_label_class() | Get field label class. |
get_field_css_class() | Get field CSS class. |
get_field_action_aria_label() | Return an aria-label for a field action (delete, edit, duplicate). |
is_value_submission_array() | Whether this field expects an array during submission. |
get_input_id_from_choice_key() | Returns the input ID given the choice key for Multiple Choice and Image Choice fields. |
get_choice_id_from_input_key() | Returns the choice ID given the input key for Multiple Choice and Image Choice fields. |
is_value_submission_empty() | Used to determine the required validation result. |
is_value_empty() | Is the given value considered empty for this field. |
validate() | Override this method to perform custom validation logic. |
set_required_error() | Sets the failed_validation and validation_message properties for a required field error. |
prepare_complex_validation_value() | Override to modify the value before it's used to generate the complex validation message. |
complex_validation_message() | Create a validation message for a required field with multiple inputs. |
get_input_property() | Gets a property value from an input. |
get_value_submission() | Retrieve the field value on submission. |
get_input_value_submission() | Retrieve the input value on submission. |
get_entry_inputs() | Override and return null if a multi-input field value is to be stored under the field ID instead of the individual input IDs. |
get_repeater_inputs() | Returns inputs structure for use in repeater fields. |
get_value_save_entry() | Sanitize and format the value before it is saved to the Entry Object. |
get_value_save_input() | Sanitize and format the value before it is saved to the Entry Object. |
get_value_merge_tag() | Format the entry value for when the field/input merge tag is processed. Not called for the {all_fields} merge tag. |
get_value_entry_list() | Format the entry value for display on the entries list page. |
get_value_all_fields_merge_tag() | Returns the field value formatted for the {all_fields} merge tag. |
get_value_entry_detail() | Format the entry value for display on the entry detail page and for the {all_fields} merge tag. |
get_value_export() | Format the entry value before it is used in entry exports and by framework add-ons using GFAddOn::get_field_value(). |
filter_input_value() | Apply the gform_get_input_value filter to an entry's value. |
get_selected_choice_output() | Prepares the selected choice from the entry for output. |
get_selected_choice() | Returns the choice array for the entry value. |
get_conditional_logic_event() | Maybe return the input attribute which will trigger evaluation of conditional logic rules which depend on this field. |
get_tabindex() | Maybe return the tabindex attribute. |
get_field_placeholder_attribute() | If the field placeholder property has a value return the input placeholder attribute. |
get_placeholder_value() | Process merge tags in the placeholder and return it. |
get_input_placeholder_attribute() | If the input placeholder property has a value return the input placeholder attribute. |
get_input_placeholder_value() | If configured retrieve the input placeholder value. |
get_input_label() | Return the custom label for an input. |
get_input_label_class() | Get the input label classes. When no custom label and placeholder for an input, we apply the |
is_form_editor() | Determine if the current location is the form editor. |
is_entry_detail() | Determine if the current location is the entry detail page. |
is_entry_detail_edit() | Determine if the current location is the edit entry page. |
has_calculation() | Is this a calculated product field or a number field with a calculation enabled and formula configured. |
is_description_above() | Determines if the field description should be positioned above or below the input. |
is_sub_label_above() | Determines if the field sub labels should be positioned above or below the input. |
is_validation_above() | Determines if the field validation message should be positioned above or below the input. |
set_modifiers() | Store the modifiers so they can be accessed in get_value_entry_detail() when preparing the content for the {all_fields} output. |
get_modifiers() | Retrieve the merge tag modifiers. |
get_input_type() | Retrieves the field input type. |
add_button() | Adds the field button to the specified group. |
get_admin_buttons() | Returns the field admin buttons for display in the form editor. |
get_required_indicator() | Get the text that indicates a field is required. |
get_hidden_admin_markup() | Get markup to show that the field is hidden in the form editor |
get_field_label() | Retrieve the field label. |
get_first_input_id() | Returns the input ID to be assigned to the field label for attribute. |
maybe_add_aria_describedby() | Set the aria-describedby attribute for an input if it is the first input in a fieldset |
get_field_autocomplete_attribute() | Get the autocomplete attribute for the field. |
get_input_autocomplete_attribute() | If the input autocomplete property has a value return the input autocomplete attribute. |
parse_autocomplete_attributes() | Parse a comma-separated list of autocomplete attributes. |
get_description() | Returns the markup for the field description. |
get_aria_describedby() | If a field has a description, the aria-describedby attribute for the input field is returned. |
get_aria_attributes() | Generates aria-describedby, aria-invalid and aria-required attributes for field inputs. |
should_be_validated() | Whether this field has been submitted, |
is_state_validation_supported() | Determines if this field will be processed by the state validation. |
skip_state_validation_if_blank() | Indicates if state validation should be skipped if the submitted value is blank. |
is_state_valid() | Determines the if the field has been tampered with before submission. |
get_state_validation_message() | Returns the validation message to be applied when the field has failed state validation. |
get_choice_option_value() | Gets a field choice value, including the price if enabled. |
get_values_for_state_hash() | Prepares the value that will be hashed on form display as part of the state. |
get_value_for_state_validation() | Returns the value to use when the state is validated. |
get_inputs_describedby_attributes() | Generates an array that contains aria-describedby attribute for each input. |
get_inputs_required_attributes() | Generates an array that contains aria-required attributes for each input. |
get_inputs_invalid_attributes() | Generates an array that contains aria-invalid attributes for each input. |
get_value_default_if_empty() | Returns the field default value if the field does not already have a value. |
get_value_default() | Retrieve the field default value. |
get_css_grid_class() | Get the appropriate CSS Grid class for the column span of the field. |
register_form_init_scripts() | Registers the script returned by get_form_inline_script_on_page_render() for display on the front-end. |
strip_script_tag() | Strip unsafe tags from the field value. |
allow_html() | Override this if the field should allow html tags to be saved with the entry value. Default is false. |
sanitize_entry_value() | Fields should override this method to implement the appropriate sanitization specific to the field type before the value is saved. |
sanitize_settings() | Forces settings into expected values while saving the form object. |
sanitize_settings_choices() | Sanitize the field choices property. |
sanitize_settings_conditional_logic() | Sanitize the field conditional logic object. |
sanitize_autocomplete_attributes() | Sanitize autocomplete attributes by checking them against whitelist. |
maybe_wp_kses() | Applies wp_kses() if the current user doesn't have the unfiltered_html capability |
get_allowable_tags() | Returns the allowed HTML tags for the field value. |
post_convert_field() | Actions to be performed after the field has been converted to an object. |
get_size_choices() | Returns the choices for the Field Size setting. |
get_filter_settings() | Returns the filter settings for the current field. |
get_filter_operators() | Returns the filter operators for the current field. |
get_filter_values() | Returns the filters values setting for the current field. |
get_filter_sub_filters() | Returns the sub-filters for the current field. |
get_product_quantity_label() | Get the product quantity label. |
get_extra_entry_metadata() | Returns an array of key value pairs to be saved to the entry meta after saving/updating the entry. |
disable_ajax_reload() | Decides if the field markup should not be reloaded after AJAX save. |
Method Reference
has_persistent_choices()
public function has_persistent_choices()
Whether the choice field has entries that persist after changing the field type.
Returns
boolean
Since: 2.9
Source: includes/fields/class-gf-field.php:111
__get()
public function&__get( $key )
The getter method of the field property.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The field property. |
Returns
bool|mixed
Since:
unknown2.4.19(Add whitelist for the size property.)
Source: includes/fields/class-gf-field.php:234
set_context_property()
public function set_context_property( $property_key, $value )
Set a context property for this field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$property_key | array | string | ||
$value | mixed |
Returns
void
Since:
Source: includes/fields/class-gf-field.php:283
set_input_validation_state()
public function set_input_validation_state( $input_id, $is_valid )
Set the validation state for a single input within this field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$input_id | string | ||
$is_valid | bool |
Returns
void
Since: 2.5.10
Source: includes/fields/class-gf-field.php:318
get_default_properties()
public function get_default_properties()
Get default properties for a field.
Used to populate a field with default properties if any properties are required for a field to function correctly.
Returns
array
Since: 2.7.4
Source: includes/fields/class-gf-field.php:433
get_form_editor_field_title()
public function get_form_editor_field_title()
Returns the field title.
Returns
string
Source: includes/fields/class-gf-field.php:445
get_form_editor_field_icon()
public function get_form_editor_field_icon()
Returns the field's form editor icon.
This could be an icon url or a gform-icon class.
Returns
string
Since: 2.5
Source: includes/fields/class-gf-field.php:458
get_form_editor_field_type_icon()
public function get_form_editor_field_type_icon()
Returns the form editor icon for the field type.
Sometimes the field type and the input type are not the same, but we want the field type icon.
Returns
string
Since: 2.9.0
Source: includes/fields/class-gf-field.php:471
get_form_editor_field_description()
public function get_form_editor_field_description()
Returns the field's form editor description.
Returns
string
Since: 2.5
Source: includes/fields/class-gf-field.php:489
get_required_inputs_ids()
public function get_required_inputs_ids()
Defines the IDs of required inputs.
Returns
string[]
Since: 2.5
Source: includes/fields/class-gf-field.php:500
get_form_editor_button()
public function get_form_editor_button()
Returns the field button properties for the form editor. The array contains two elements:
'group' => 'standard_fields' // or 'advanced_fields', 'post_fields', 'pricing_fields' 'text' => 'Button text'
Built-in fields don't need to implement this because the buttons are added in sequence in GFFormDetail
Returns
array
Source: includes/fields/class-gf-field.php:513
get_form_editor_field_settings()
public function get_form_editor_field_settings()
Returns the class names of the settings which should be available on the field in the form editor.
Returns
array
Source: includes/fields/class-gf-field.php:527
is_conditional_logic_supported()
public function is_conditional_logic_supported()
Override to indicate if this field type can be used when configuring conditional logic rules.
Returns
bool
Source: includes/fields/class-gf-field.php:536
get_form_editor_inline_script_on_page_render()
public function get_form_editor_inline_script_on_page_render()
Returns the scripts to be included for this field type in the form editor.
Returns
string
Source: includes/fields/class-gf-field.php:545