Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- 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 ){
- $acceptance_form_id = 16777; // ID of acceptance form
- $commission_id_field = "hidden-2"; // ID of the hidden field on acceptance form that keeps commission entry ID
- $error_msg = 'This song commission is already accepted!'; // custom error message
- if( empty( $submit_errors ) && ( $form_id == $acceptance_form_id ) ) {
- foreach( $field_data_array as $field ){
- if( $field['name'] === $commission_id_field ) {
- global $wpdb;
- $GLOBALS['comm_error'] = 'available';
- $table_meta = $wpdb->prefix . 'frmt_form_entry_meta';
- $table_entry = $wpdb->prefix . 'frmt_form_entry';
- $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 ) ) ;
- if ( $found ) {
- error_log( $field['name'] . " " . $field['value'] );
- error_log( $found );
- $submit_errors[]['submit'] = $error_msg;
- $GLOBALS['comm_error'] = $error_msg;
- }
- break;
- }
- }
- }
- return $submit_errors;
- }, 10, 3);
- add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error', 10, 1 );
- function wpmudev_invalid_form_error( $invalid_form_message ){
- if ( ( ! empty( $GLOBALS['comm_error'] ) ) && ( $GLOBALS['comm_error'] !== 'available' ) ) {
- $invalid_form_message = $GLOBALS['comm_error'];
- }
- return $invalid_form_message;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement