This hook can be used to determine whether a submitted value for an element is valid. Note that if the field is empty and not required then validation will be skipped, so this hook will not be run in that situation.
quform_element_valid_X_X
This hook is run for a single element.
Example
12
3
4
5
6
7
8
| add_filter('quform_element_valid_1_3', function ($valid, $value, Quform_Element_Field $element) { if ($value != 'Foo') { $element->addError('The value is not Foo'); $valid = false; } return $valid; }, 10, 3); |
add_filter('quform_element_valid_1_3', function ($valid, $value, Quform_Element_Field $element) { if ($value != 'Foo') { $element->addError('The value is not Foo'); $valid = false; } return $valid; }, 10, 3);
- On line 1, change
1_3
to the element unique ID
1
2
3
4
5
6
7
8
9
10 | function my_element_valid($valid, $value, Quform_Element_Field $element) { if ($value != 'Foo') { $element->addError('The value is not Foo'); $valid = false; } return $valid; } add_filter('quform_element_valid_1_3', 'my_element_valid', 10, 3); |
function my_element_valid($valid, $value, Quform_Element_Field $element) { if ($value != 'Foo') { $element->addError('The value is not Foo'); $valid = false; } return $valid; } add_filter('quform_element_valid_1_3', 'my_element_valid', 10, 3);
- On line 10, change
1_3
to the element unique ID
quform_element_valid
This hook is run for all elements.
Example
1 2 3 4 5 6 7 8 | add_filter('quform_element_valid', function ($valid, $value, Quform_Element_Field $element) { if ($value != 'Foo') { $element->addError('The value is not Foo'); $valid = false; } return $valid; }, 10, 3); |
add_filter('quform_element_valid', function ($valid, $value, Quform_Element_Field $element) { if ($value != 'Foo') { $element->addError('The value is not Foo'); $valid = false; } return $valid; }, 10, 3);
1 2 3 4 5 6 7 8 9 10 | function my_element_valid($valid, $value, Quform_Element_Field $element) { if ($value != 'Foo') { $element->addError('The value is not Foo'); $valid = false; } return $valid; } add_filter('quform_element_valid', 'my_element_valid', 10, 3); |
function my_element_valid($valid, $value, Quform_Element_Field $element) { if ($value != 'Foo') { $element->addError('The value is not Foo'); $valid = false; } return $valid; } add_filter('quform_element_valid', 'my_element_valid', 10, 3);
Parameters
$valid
–boolean
– whether the field is currently valid or not$value
–mixed
– the current field value (data type depends on element type)$element
–Quform_Element_Field
– the element instance