formcierge_pre_submission_validate
Filter
Since v1.0.0
Run custom validation before Formcierge's built-in field validation. Return a WP_Error to reject the submission with a custom message.
Parameters
$data
array
Associative array of submitted field values.
$form_id
int
The form ID.
includes/Core/FormValidator.php
Basic Usage
add_filter( 'formcierge_pre_submission_validate', function ( $data, $form_id ) {
$email = $data['field_email'] ?? '';
if ( str_ends_with( $email, '@banned-domain.com' ) ) {
return new WP_Error( 'blocked_email', 'This email domain is not allowed.' );
}
return $data;
}, 10, 2 );
Real-World Examples
Verify a CAPTCHA token server-side
add_filter( 'formcierge_pre_submission_validate', function ( $data, $form_id ) {
$token = $data['captcha_token'] ?? '';
if ( ! my_verify_captcha( $token ) ) {
return new WP_Error( 'captcha_failed', 'CAPTCHA verification failed.' );
}
return $data;
}, 10, 2 );