Advertisement
adczk

Forminator - allow single acceptance of commission submission (specific goal code)

Jun 26th, 2023
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {
  4.     exit;
  5. } elseif ( defined( 'WP_CLI' ) && WP_CLI ) {
  6.     return;
  7. }
  8.  
  9. add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ){
  10.    
  11.     $acceptance_form_id = 16777; // ID of acceptance form
  12.     $commission_id_field = "hidden-2"; // ID of the hidden field on acceptance form that keeps commission entry ID
  13.     $error_msg = 'This song commission is already accepted!'; // custom error message
  14.    
  15.    
  16.     if( empty( $submit_errors ) && ( $form_id == $acceptance_form_id ) ) {
  17.                
  18.         foreach( $field_data_array as $field ){
  19.            
  20.             if( $field['name'] === $commission_id_field ) {
  21.        
  22.                 global $wpdb;
  23.                
  24.                 $GLOBALS['comm_error'] = 'available';
  25.                
  26.                 $table_meta = $wpdb->prefix . 'frmt_form_entry_meta';
  27.                 $table_entry = $wpdb->prefix . 'frmt_form_entry';
  28.                 $found = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) 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;", $field['name'], $field['value'], $form_id ) ) ;
  29.                    
  30.                 if ( $found ) {
  31.                    
  32.                     error_log( $field['name'] . " " . $field['value'] );
  33.                    
  34.                     error_log( $found );
  35.                    
  36.                    
  37.                     $submit_errors[]['submit'] = $error_msg;
  38.                     $GLOBALS['comm_error'] = $error_msg;
  39.                 }
  40.                 break;
  41.             }
  42.         }
  43.     }
  44.     return $submit_errors;
  45. }, 10, 3);
  46.  
  47.  
  48.  
  49. add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error', 10, 1 );
  50. function wpmudev_invalid_form_error( $invalid_form_message ){
  51.    
  52.    
  53.     if ( ( ! empty( $GLOBALS['comm_error'] ) ) && ( $GLOBALS['comm_error'] !== 'available' ) ) {
  54.         $invalid_form_message = $GLOBALS['comm_error'];
  55.     }
  56.            
  57.     return $invalid_form_message;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement