Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter( 'forminator_custom_form_submit_errors', 'check_form_duplicate_submission_data', 99, 3 );
- function check_form_duplicate_submission_data( $submit_errors, $form_id, $field_data_array ) {
- $form_ids = array( 22246 ); // form IDs - one or more; if more - separate numbers with commas
- $fields_to_check = array(
- 'phone-2' => 'phone-1',
- 'email-2' => 'email-1',
- ); // field pairs to check - each key-value pair represents a pair of fields to check for duplicates
- $field_delete = 'checkbox-1'; // id of "DELETE" field
- $err_msg = 'No registration was found with the given data'; // custom error message
- $found_duplicate = false;
- $check = false;
- if ( !in_array( $form_id, $form_ids ) ) {
- return $submit_errors; // just bail out and skip checks
- }
- foreach ( $fields_to_check as $field_to_check => $field_to_compare ) {
- $field_to_check_value = '';
- $field_to_compare_value = '';
- foreach( $field_data_array as $key => $value ) {
- $field_name = $value['name'];
- if ($field_name == $field_delete) {
- $check = true;
- }
- if ( $field_name === $field_to_check ) {
- $field_to_check_value = $value['value'];
- } elseif ( $field_name === $field_to_compare ) {
- $field_to_compare_value = $value['value'];
- }
- }
- if ($check) {
- if ( $field_to_check_value && $field_to_compare_value && $field_to_check_value === $field_to_compare_value ) {
- $entries = Forminator_Form_Entry_Model::select_count_entries_by_meta_field( $form_id, $field_to_compare, $field_to_compare_value, '*' );
- if ( $entries ) {
- $submit_errors[][$field_to_check] = $err_msg;
- $found_duplicate = true;
- }
- }
- }
- }
- if ( !$found_duplicate ) {
- $submit_errors[]['general'] = $err_msg;
- }
- return $submit_errors;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement