Hi @sashimisensei,
Please try the following workaround on a dev/staging website, I hope that helps.
<?php
add_filter( 'forminator_custom_form_submit_errors', 'wpmudev_formi_hours_submission_check', 10, 3 );
function wpmudev_formi_hours_submission_check( $submit_errors, $module_id, $field_data_array ) {
if ( $module_id != 1230 ) { // Please change the form ID.
return $submit_errors;
}
$submitted_data = wp_list_pluck( $field_data_array, 'value', 'name' );
if ( ! empty( $submitted_data['date-1'] ) && isset( $submitted_data['time-1']['hours'] ) && isset( $submitted_data['time-1']['minutes'] ) ) {
$selected_time = $submitted_data['date-1'] . ' ' . $submitted_data['time-1']['hours'] . ':' . $submitted_data['time-1']['minutes'];
$current_date = date( 'Y-m-d G:i' );
$start_date = new DateTime( $current_date );
$since_start = $start_date->diff( new DateTime( $selected_time ) );
$hours = $since_start->h;
$minutes = $since_start->i;
if ( $hours < 6 ) { // Please change the number of hours 6 to your number of hours
$submit_errors[]['submit'] = 'Can not cancel it now.';
$GLOBALS['hour_error'] = true;
} else {
$GLOBALS['hour_error'] = false;
}
}
return $submit_errors;
}
add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error_response_submit', 10, 2 );
function wpmudev_invalid_form_error_response_submit( $invalid_form_message, $form_id ){
if ( $form_id != 1230 ) {
return $invalid_form_message;
}
if ( $GLOBALS['hour_error'] ) {
$invalid_form_message = __( 'Can not cancel it now.', 'forminator' );
}
return $invalid_form_message;
}
The code could be added as a mu-plugin: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
Make sure to update the form ID 1230 in the above code with your form ID.
Please feel free to get back to us if you need any further assistance.
Kind Regards,
Nebu John