Skip to content

Instantly share code, notes, and snippets.

@patrickfreitasdev
Last active November 6, 2022 13:41
Show Gist options
  • Select an option

  • Save patrickfreitasdev/12e75dd199799532875b319871904bf1 to your computer and use it in GitHub Desktop.

Select an option

Save patrickfreitasdev/12e75dd199799532875b319871904bf1 to your computer and use it in GitHub Desktop.
<?php
add_filter('forminator_custom_form_submit_errors', 'my_custom_form_validation', 10, 3);
function my_custom_form_validation($submit_errors, $form_id, $field_data_array) {
// Skip if is not the correct form
if( (int) $form_id !== 49 ){
return;
}
$fields = [];
$fields[] = $_POST['email-1'];
$fields[] = $_POST['email-2'];
// Check if both emails are the same
if (count(array_unique($fields)) !== 1) {
// Custom error
$submit_errors[][ 'email-2'] = __( 'Emails does not match' );
}
// Always return $submit_errors
return $submit_errors;
}
@patrickfreitasdev
Copy link
Author

Hi @inspiredearth I hope you are doing well.

It is the default behaviour on Forminator, on top of Form it shows the "Error:... " and on the field level it will show what you define at:

$submit_errors[][ 'email-2'] = __( 'Emails does not match' );

However, feel free to open a ticket on wordpress.org > Forminator > Support and we can take a look if this can be changed.

@inspiredearth
Copy link

Hi @patrickfreitasdev , Thanks for that info.
It seems to be that the current wording isn't ideal. It makes it sound like there is an error with the form itself.
I suspect it would be clearer and less ambiguous if it stated something like, "Submitted form data is invalid. Check for error messages within the form". Something along those lines.

I'll post a support ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment