hollosipeter

checkbox_deletion_CHECKED_forminator_custom_form_submit_errors

Apr 20th, 2023
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | Source Code | 0 0
  1. <?php
  2.  
  3. add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ){
  4. $your_list_forms = [22246];
  5. if ( empty( $submit_errors ) && in_array( $form_id, $your_list_forms ) ) {
  6. $submitted_fields = wp_list_pluck( $field_data_array, 'value', 'name' );
  7. if ( empty( $submitted_fields['checkbox-2'] ) ) {
  8. return $submit_errors;
  9. }
  10.  
  11. $your_unique_field_name = 'email-2';
  12. $your_unique_field_phone = 'phone-2';
  13. $your_error_msg = 'There is no application in progress with the given data / A megadott adatokkal nincs folyamatban lévő jelentkezés';
  14. $GLOBALS['reg_error'] = false;
  15. foreach ( $field_data_array as $field ) {
  16. if ( $field['name'] === $your_unique_field_name ) {
  17. global $wpdb;
  18. $table_meta = $wpdb->prefix . 'frmt_form_entry_meta';
  19. $table_entry = $wpdb->prefix . 'frmt_form_entry';
  20. 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 = %s AND m.meta_value=%s AND e.form_id = %d LIMIT 1;", 'email-1', $field['value'], $form_id ) ) ) {
  21. $submit_errors[]['submit'] = $your_error_msg;
  22. $GLOBALS['reg_error'] = true;
  23. break;
  24. }
  25. }
  26.  
  27. if ( $field['name'] === $your_unique_field_phone ) {
  28. global $wpdb;
  29. $table_meta = $wpdb->prefix . 'frmt_form_entry_meta';
  30. $table_entry = $wpdb->prefix . 'frmt_form_entry';
  31. 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 = %s AND m.meta_value=%s AND e.form_id = %d LIMIT 1;", 'phone-1', $field['value'], $form_id ) ) ) {
  32. $submit_errors[]['submit'] = $your_error_msg;
  33. $GLOBALS['reg_error'] = true;
  34. break;
  35. }
  36. }
  37. }
  38. }
  39. return $submit_errors;
  40. }, 10, 3);
  41.  
  42. add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error_response', 10, 2 );
  43. function wpmudev_invalid_form_error_response( $invalid_form_message, $form_id ){
  44. if ( $form_id != 22246 ) {
  45. return $invalid_form_message;
  46. }
  47.  
  48. if ( $GLOBALS['reg_error'] ) {
  49. $invalid_form_message = __( 'There is no application in progress with the given data / A megadott adatokkal nincs folyamatban lévő jelentkezés', 'forminator' );
  50. }
  51.  
  52. return $invalid_form_message;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment