Quantcast
Channel: WordPress.org Forums » [Forminator Forms – Contact Form, Payment Form & Custom Form Builder] Support
Viewing all articles
Browse latest Browse all 1601

Validating list of numbers with forminator_custom_form_submit_errors

$
0
0

Replies: 0

Hi,

I’m using the following mu-plugins to validate a list of numbers, but when I go to the form it doesn’t work.

add_filter( 'forminator_custom_form_submit_errors', 'validate_numbers', 10, 3 );
function validate_numbers( $submit_errors, $form_id, $field_data_array ) {
if ( $form_id !== 94 ) {
return $submit_errors;
}

$valid_numbers = array('132', '133', '134');

foreach ( $field_data_array as $field ) {
if ( $field['name'] === 'text-1' ) {
$numbers_entered = trim($field['value']);
if ( !in_array( $numbers_entered, $valid_numbers ) ) {
$submit_errors[] = array(
'field' => 'text-1',
'message' => 'The number entered is invalid. Only 132, 133, or 134 are allowed.',
);
}
}
}

return $submit_errors;
}

I’m using a text field with a 3-character limit, the mu-plugins file is created and has the correct permissions, it appears under Must-Use, but I don’t understand why it’s not working.

I need this code to validate all 3 digits, for the field to only accept numbers, and for at least 3 digits to be entered, but the most important thing is that it works.

Thanks.


Viewing all articles
Browse latest Browse all 1601

Trending Articles