Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: [Forminator] Check submission duplicated data
- * Plugin URI: https://premium.wpmudev.org/
- * Description: check if entry with same data (per defined field) already exists and prevent such duplicated data submission
- * Author: adczk
- * Author URI: https://premium.wpmudev.org/
- * License: GPLv2 or later
- *
- * Tested with Forminator 1.22.1
- *
- *
- * USE AS MU PLUGIN
- *
- * config explained in code comment
- *
- */
- 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( 2245, 123 ); // form IDs - one or more; if more - separate numbers with commas
- $check_field_id = 'checkbox-1'; // ID of the field to determine if to do the data check or skip it; must be SINGLE checkbox
- $fields_ids = array( 'phone-1', 'email-1' ); // IDs of fields to check, one or more, if more - separate with commas
- $err_msg = 'Duplicated entry!'; // custom error message
- // do not edit below
- $check = false;
- if ( !in_array( $form_id, $form_ids ) ) {
- return $submit_errors; // just bail out and skip checks
- }
- foreach( $field_data_array as $key => $value ) {
- $field_name = $value['name'];
- if ( $field_name == $check_field_id ) {
- $check = true;
- }
- if ( in_array( $field_name, $fields_ids ) && $check ) {
- $entries = Forminator_Form_Entry_Model::select_count_entries_by_meta_field( $form_id, $field_name, $value['value'], '*' );
- if ( $entries ) {
- $submit_errors[][$field_name] = $err_msg;
- }
- }
- }
- return $submit_errors;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement