Last active
September 29, 2024 08:15
-
-
Save patrickfreitasdev/ec5d3d44f504e42f92891346520d3bcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This add a simple verification for selected fields if those have own value | |
**/ | |
add_filter('forminator_custom_form_submit_errors', 'verification_for_unique_values_forminator_wp', 10, 3); | |
function verification_for_unique_values_forminator_wp($submit_errors, $form_id, $field_data_array) { | |
$forms = ['2071', '1020']; | |
$fields = ['name-1', 'email-1', 'phone-1']; | |
$unique = []; | |
// Skip if is not the correct form | |
if( !in_array( $form_id, $forms ) ){ | |
return; | |
} | |
//Make sure the received value are lowecase | |
foreach($fields as $field){ | |
$unique[] = strtolower( $_POST[$field] ); | |
} | |
// verification for duplicated values | |
if( count($unique) !== count(array_flip($unique))) { | |
$submit_errors[][ 'name-1'] = __( 'Please, verify any duplicated entry' ); | |
} | |
// Always return $submit_errors | |
return $submit_errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment