Skip to main content

Gravity_Forms\Gravity_Forms\Settings\Fields\Base

Source: includes/settings/fields/class-base.php:12

Details

  • Kind: class

  • Namespace: Gravity_Forms\Gravity_Forms\Settings\Fields

  • Implements: ArrayAccess

Properties

PropertyTypeDescription
$typestringField type.
$namestringField name.
$labelstringField label.
$classstringField CSS class.
$requiredboolField requirement.
$fieldsBase{}Nested fields for field.
$inputsBase{}Child inputs for field.
$default_valuestring | arrayDefault value of field.
$dependencyarrayDependencies required to display field.
$save_callbackcallableFunction to run when field is saved.
$validation_callbackcallableFunction to run when field is being validated.
$legacy_validation_callbackcallableLegacy add-on method to call when a field is being validated.
$settingsSettings
$encryptboolUsed to check if encryption is suppported.
$idintField id.
$callbackcallableField callback.
$feedback_callbackcallableField feedback callback.
$hiddenstringField hidden property.
$htmlstringField html.
$descriptionstringField description.
$conditional_descriptionsarrayDescriptions to display conditionally based on the field's current value.
$tooltipstringField tooltip.
$after_inputstringField content after input.
$choicesarrayField choices.
$taxonomystringField taxonomy.
$valuestringField value.
$placeholderstringField placeholder
$checkboxarrayCheckbox input attributes
$selectarraySelect input attributes
$readonlystringWhether field is readonly
$errorstring | falseField error message.
$onchangestring | falseField onchange attribute.
$current_render_callbackcallableCurrent function rendering field.

Methods

MethodDescription
__construct()Initialize field.
scripts()Register scripts to enqueue when displaying field.
styles()Register styles to enqueue when displaying field.
prepare_markup()Render field.
markup()Prepare field markup.
get_attributes()Returns a set of HTML attributes to be added to the HTML element.
get_choice_attributes()Parses the properties of a field choice and returns a set of HTML attributes to be added to the HTML element.
get_describer()Get describer element(s) for field.
get_description()Renders the description text for a field, followed by any conditional descriptions.
get_conditional_descriptions()Renders conditional descriptions that show/hide based on the field's current value.
get_container_classes()Gets the classes to apply to the field container.
has_icons()Determines if any of the available field choices have an icon.
has_tag()Determines if any of the available field choices have a tag.
validate()Validate posted field value.
handle_validation()Validate posted field value.
is_valid()Validate posted field value.
do_validation()Validate posted field value.
is_choice_valid()Determine if the current choice is a match for the submitted field value.
get_error()Get error message for field.
get_error_icon()Gets the validation error icon.
set_error()Set error message for field.
get_choices()Helper method to return choices for field.
get_value()Helper method to retrieve field value.
save_field()Get field value before saving.
save()Modify field value before saving.
get_parsed_name()Parses the field's name to determine whether it's a simple string or a multi-dimensional array.

Method Reference

__construct()

public function __construct( $props, $settings )

Initialize field.

Parameters

NameTypeDefaultDescription
$propsarrayField properties.
$settingsSettingsSettings instance.

Since: 2.5

Source: includes/settings/fields/class-base.php:329

scripts()

public function scripts()

Register scripts to enqueue when displaying field.

Returns

  • array

Since: 2.5

Source: includes/settings/fields/class-base.php:355

styles()

public function styles()

Register styles to enqueue when displaying field.

Returns

  • array

Since: 2.5

Source: includes/settings/fields/class-base.php:368

prepare_markup()

public function prepare_markup()

Render field.

Returns

  • string

Since: 2.5

Source: includes/settings/fields/class-base.php:387

markup()

public function markup()

Prepare field markup.

Returns

  • string

Since: 2.5

Source: includes/settings/fields/class-base.php:420

get_attributes()

public function get_attributes( $default=[] )

Returns a set of HTML attributes to be added to the HTML element.

Parameters

NameTypeDefaultDescription
$defaultarray[]Default set of attributes.

Returns

  • array

Since: 2.5

Source: includes/settings/fields/class-base.php:435

get_choice_attributes()

public static function get_choice_attributes( $choice, $field_attributes=[], $default_attributes=[] )

Parses the properties of a field choice and returns a set of HTML attributes to be added to the HTML element.

Parameters

NameTypeDefaultDescription
$choicearrayField choice meta.
$field_attributesarray[]Field attributes.
$default_attributesarray[]Default attributes for choice.

Returns

  • array

Since: 2.5

Source: includes/settings/fields/class-base.php:527

get_describer()

public function get_describer()

Get describer element(s) for field.

Returns

  • string

Since: 2.5

Source: includes/settings/fields/class-base.php:573

get_description()

public function get_description()

Renders the description text for a field, followed by any conditional descriptions.

Returns

  • string

Since: 2.5

Source: includes/settings/fields/class-base.php:590

get_conditional_descriptions()

public function get_conditional_descriptions()

Renders conditional descriptions that show/hide based on the field's current value.

Used to display the conditional_descriptions property. Works for select, radio, and checkbox/toggle field types.

Returns

  • string

Since: 3.0

Source: includes/settings/fields/class-base.php:609

get_container_classes()

public function get_container_classes()

Gets the classes to apply to the field container.

Returns

  • string

Since: 2.5

Source: includes/settings/fields/class-base.php:678

has_icons()

public static function has_icons( $choices=[] )

Determines if any of the available field choices have an icon.

Parameters

NameTypeDefaultDescription
$choicesarray[]

Returns

  • bool

Since: 2.5

Source: includes/settings/fields/class-base.php:719

has_tag()

public static function has_tag( $choices=[] )

Determines if any of the available field choices have a tag.

Parameters

NameTypeDefaultDescription
$choicesarray[]

Returns

  • bool

Since: 2.5.6.4

Source: includes/settings/fields/class-base.php:740

validate()

public function validate( $value )

Validate posted field value.

Run defined callback.

Parameters

NameTypeDefaultDescription
$valuearray | bool | stringPosted field value.

Since: 2.5

Deprecated: Deprecated since 2.5-beta-3. Use handle_validation() instead.

Source: includes/settings/fields/class-base.php:768

handle_validation()

public function handle_validation( $value )

Validate posted field value.

Run defined callback.

Parameters

NameTypeDefaultDescription
$valuearray | bool | stringPosted field value.

Since: 2.5-beta-3

Source: includes/settings/fields/class-base.php:782

is_valid()

public function is_valid( $value )

Validate posted field value.

Parameters

NameTypeDefaultDescription
$valuearray | bool | stringPosted field value.

Since: 2.5

Deprecated: Deprecated since 2.5-beta-3 - use do_validation() instead.

Source: includes/settings/fields/class-base.php:809

do_validation()

public function do_validation( $value )

Validate posted field value.

Parameters

NameTypeDefaultDescription
$valuearray | bool | stringPosted field value.

Since: 2.5-beta-3

Source: includes/settings/fields/class-base.php:823

is_choice_valid()

public static function is_choice_valid( $choice, $value )

Determine if the current choice is a match for the submitted field value.

Parameters

NameTypeDefaultDescription
$choicearrayThe choice properties.
$valuestring | arrayThe submitted field value.

Returns

  • bool

Since: 2.5

Source: includes/settings/fields/class-base.php:842

get_error()

public function get_error()

Get error message for field.

Returns

  • string

Since: 2.5

Source: includes/settings/fields/class-base.php:857

get_error_icon()

public function get_error_icon()

Gets the validation error icon.

Returns

  • string

Since: 2.5

Source: includes/settings/fields/class-base.php:870

set_error()

public function set_error( $error_message='' )

Set error message for field.

Parameters

NameTypeDefaultDescription
$error_messagestring''Error message.

Since: 2.5

Source: includes/settings/fields/class-base.php:886

get_choices()

public function get_choices( $choices=false )

Helper method to return choices for field.

Parameters

NameTypeDefaultDescription
$choicesarray | callable | boolfalseExisting choices. Defaults to field property.

Returns

  • array

Since: 2.5

Source: includes/settings/fields/class-base.php:912

get_value()

public function get_value()

Helper method to retrieve field value.

Returns

  • array | bool | string

Since: 2.5

Source: includes/settings/fields/class-base.php:942

save_field()

public function save_field( $field_values, $field_value )

Get field value before saving.

Parameters

NameTypeDefaultDescription
$field_valuesarrayPosted field values.
$field_valuearray | bool | stringPosted value for field.

Returns

  • array

Since: 2.5

Source: includes/settings/fields/class-base.php:958

save()

public function save( $value )

Modify field value before saving.

Parameters

NameTypeDefaultDescription
$valuearray | bool | string

Returns

  • array | bool | string

Since: 2.5

Source: includes/settings/fields/class-base.php:988

get_parsed_name()

public function get_parsed_name()

Parses the field's name to determine whether it's a simple string or a multi-dimensional array.

Examples:

  • A string of gravityformsapi will return gravityformsapi.
  • A string of gravityformsapi[log_level] will return an array of [ 'gravityformsapi', 'log_level' ].

Returns

  • string | array

Since: 2.5

Source: includes/settings/fields/class-base.php:1079