Created
June 16, 2022 15:56
-
-
Save patrickfreitasdev/8b82ae877640f2e2796cd2d5b332ca83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) { | |
| if( $form_id != 361 ) { | |
| return $submit_errors; | |
| } | |
| $last_entry = ''; | |
| // Change this to the message that you want to show. | |
| $message = 'Booking has been done for the day. Please book for another day.'; | |
| foreach( $field_data_array as $key => $value ){ | |
| if( $value['name'] == 'date-1' ){ | |
| if( $value['value'] != '' ){ | |
| $last_entry = wpmudev_get_last_entry_by_date( $form_id, $value['value'] ); | |
| } | |
| } | |
| } | |
| if ( ! empty( $last_entry ) ) { | |
| $submit_errors[]['submit'] = $message; | |
| } | |
| return $submit_errors; | |
| },15,3); | |
| add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error', 10, 2 ); | |
| function wpmudev_invalid_form_error( $invalid_form_message, $form_id ){ | |
| if( $form_id != 361 ) { | |
| return $invalid_form_message; | |
| } | |
| $last_entry = ''; | |
| if( isset( $_POST ) ){ | |
| $date = isset( $_POST['date-1'] ) ? sanitize_text_field( $_POST['date-1'] ) : ''; | |
| if( $date ){ | |
| $last_entry = wpmudev_get_last_entry_by_date( $form_id, $date ); | |
| } | |
| } | |
| if ( ! empty( $last_entry ) ) { | |
| $invalid_form_message = __( 'Booking has been done for the day. Please book for another day.', 'forminator' ); | |
| } | |
| return $invalid_form_message; | |
| } | |
| function wpmudev_get_last_entry_by_date( $form_id, $date ){ | |
| global $wpdb; | |
| $table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY_META ); | |
| $entry_table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY ); | |
| $sql = "SELECT m.`entry_id` FROM {$table_name} m LEFT JOIN {$entry_table_name} e ON(e.`entry_id` = m.`entry_id`) WHERE e.`form_id` = %d AND m.`meta_key` = %s AND m.`meta_value` = %s order by m.`meta_id`"; | |
| $entry_id = $wpdb->get_var( $wpdb->prepare( $sql, $form_id, 'date-1', $date ) ); | |
| if ( $entry_id ) { | |
| return $entry_id; | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment