Restrict form submissions on duplication of text field – BY CLASS OF THE FIELD
-
Hi guys!
I’m meaning to ask you guys about this issue for a lng time and always forget:
Some time ago I needed to restrict form submissions on duplication of text field (CPF, which is a social security number equivalent here in Brazil).
You guys gave me this snippet, that works flawlessly:<?php /** * Plugin Name: [Forminator] - Limit the submition by email. * Description: [Forminator] - Limit the submition by email. * Author: Thobk @ WPMUDEV * Author URI: https://premium.wpmudev.org * License: GPLv2 or later */ if ( ! defined( 'ABSPATH' ) ) { exit; } elseif ( defined( 'WP_CLI' ) && WP_CLI ) { return; } add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ){ $your_list_forms = [28080,28152,29432,29863,30051,31881,32319,33093,33423,33523,33588,33636,33691,33741,33764,33777,33835,33866,33879,33881,33908,33936]; if( empty( $submit_errors ) && in_array( $form_id, $your_list_forms ) ){ $your_unique_field_name = 'text-1'; $your_error_msg = 'Já existe uma inscri??o com esse CPF.'; foreach( $field_data_array as $field ){ if( $field['name'] === $your_unique_field_name ){ global $wpdb; $table_meta = $wpdb->prefix . 'frmt_form_entry_meta'; $table_entry = $wpdb->prefix . 'frmt_form_entry'; if( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(1) FROM $table_meta as m LEFT JOIN $table_entry as e ON m.entry_id = e.entry_id WHERE m.meta_key = 'text-1' AND m.meta_value=%s AND e.form_id = %d LIMIT 1;", $field['value'], $form_id ) ) ){ $submit_errors[][$your_unique_field_name] = $your_error_msg; } break; } } } return $submit_errors; }, 10, 3);
My problem is: as you can see, I have now a very long stream of form ID’s in what this code must act on, and this code act only in those forms AND in the field with the name ‘text-1’.
What I need: that this code doesn’t need the forms ID’s to work on the form AND it doesn’t target the field’s name, but instead the field’s class. That way I don’t have to edit the snippet every new form, and some times I delete the first text field that I create and then I have to restar the form creation by scratch because the next text fields are named sequencially from 2 and forth.
Is possible to edit this code do exaclty the same function as does now, but without the need to insert the form’s ID AND targeting a specific custom class atached to any text field instead of the field’s name?
Thanks in advance, and again: huge fan, u guys rock!
- The topic ‘Restrict form submissions on duplication of text field – BY CLASS OF THE FIELD’ is closed to new replies.