Validates a field value for an element.
Description
See also
Parameters
- $value
-
(mixed) (Required) The value to validate. It is already unslashed when it arrives here.
- $element
-
(awsmug\Torro_Forms\DB_Objects\Elements\Element) (Required) Element to validate the field value for.
- $submission
-
(awsmug\Torro_Forms\DB_Objects\Submissions\Submission) (Required) Submission the value belongs to.
Return
(mixed|WP_Error) Validated value, or error object on failure.
Source
File: src/db-objects/elements/element-types/base/multiplechoice.php
public function validate_field( $value, $element, $submission ) { $settings = $this->get_settings( $element ); $value = (array) $value; if ( ! empty( $settings['required'] ) && 'no' !== $settings['required'] && empty( $value ) ) { return $this->create_error( 'value_required', __( 'You must select at least a single value here.', 'torro-forms' ), $value ); } $choices = $this->get_choices_for_field( $element ); foreach ( $value as $single_value ) { if ( ! in_array( $single_value, $choices, true ) ) { return $this->create_error( 'value_invalid_choice', __( 'You must select valid values from the list.', 'torro-forms' ), $value ); } } return $value; }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |