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.
$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.
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:308

scripts()

public function scripts()

Register scripts to enqueue when displaying field.

Returns

  • array

Since: 2.5

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

styles()

public function styles()

Register styles to enqueue when displaying field.

Returns

  • array

Since: 2.5

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

prepare_markup()

public function prepare_markup()

Render field.

Returns

  • string

Since: 2.5

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

markup()

public function markup()

Prepare field markup.

Returns

  • string

Since: 2.5

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

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:414

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:505

get_describer()

public function get_describer()

Get describer element(s) for field.

Returns

  • string

Since: 2.5

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

get_description()

public function get_description()

Renders the description text for a field.

Returns

  • string

Since: 2.5

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

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:581

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:622

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:643

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:671

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:685

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:712

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:726

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:745

get_error()

public function get_error()

Get error message for field.

Returns

  • string

Since: 2.5

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

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:773

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:789

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:815

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:845

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:861

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:891

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:982