formcierge_validate_field
Filter
Since v1.0.0
Add custom validation for any field type. Return a non-empty error string to fail validation, or null/empty to pass.
Parameters
$error
string|null
Existing error message, or null if validation has passed so far.
$value
mixed
The submitted value.
$field
array
The field definition array.
includes/Core/FormValidator.php
Basic Usage
add_filter( 'formcierge_validate_field', function ( $error, $value, $field ) {
if ( $field['type'] === 'email' && $value ) {
$domain = explode( '@', $value )[1] ?? '';
if ( $domain && ! checkdnsrr( $domain, 'MX' ) ) {
return 'Please enter a valid email address with a working domain.';
}
}
return $error;
}, 10, 3 );
Real-World Examples
Require a minimum word count on a textarea
add_filter( 'formcierge_validate_field', function ( $error, $value, $field ) {
if ( $field['id'] === 'field_message' && str_word_count( $value ) < 10 ) {
return 'Please write at least 10 words.';
}
return $error;
}, 10, 3 );