• Resolved sashimisensei

    (@sashimisensei)


    Hi. Is it possible to set the form logic to reject submission of a form if the time between the current time and the time selected in the form is less than “X” number of hours?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @sashimisensei,

    I hope you are doing well today!

    We are checking your request with our SLS (Second Line Support) team if it is possible to provide a workaround or custom code to achieve this and will inform you accordingly.

    Thanks for the patience while we are looking into this.

    Kind regards,
    Zafer

    Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi again @sashimisensei,

    Please share an export of the form with us, so that we can check further as we would like to know the settings of the Timepicker field. I mean if it is setup for 24 hours or 12 hours and if it is an input or dropdown.

    You can find more info on how to export the form here : https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export

    After exporting, please share the code using a services such as https://pastebin.com or https://justpaste.it/ which is free to use.

    Please always make sure to use such service to share the code and don’t post the code here directly as it will most likely be unusable.

    Kind regards,
    Zafer

    Thread Starter sashimisensei

    (@sashimisensei)

    Hi Zafer,

    Thanks for the reply. Please see the attached link for the form export.

    https://justpaste.it/2waem

    Regards,

    Sashimi

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @sashimisensei,

    Thank you for getting back to us.

    We have pinged the Second Level Support team to check further if a workaround could be suggested and we’ll update you here once we have feedback on this as soon as possible.

    Kind Regards,
    Nebu John

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    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

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @sashimisensei,

    Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to open a new thread if you have new queries.

    Best Regards
    Nithin

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Time-based logic’ is closed to new replies.