• Resolved Daniel Jimenez

    (@somosgrow)


    Hi guys
    I need help to configure a timepicker because I need that the available hours be from 11pm to 4am due to I’m using a form to request events in a bar.
    Is there a way to do that even if some code is needed.
    Thanks in advance for your help.
    Have a great day.

    Att:
    Daniel Jimenez

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @somosgrow

    I hope you’re well today!

    Forminator’s “Time picker” field does have option to limit available hours built-in already. You’ll find it in “Settings” tab of timepicker field settings but I think the issue here is related to the specific hours that you need to allow – by default it would only let you limit you to hours “within one day”.

    This would indeed require some custom code, if doable at all. Unfortunately, I don’t have such code at hand “ready to use” so I’ve asked our developers for advice. They’ll look into it and see if we can share some custom code snippet that would help you.

    I’d appreciate some patience as they are dealing with a lot of complex tasks on daily basis. We’ll update you here as soon as we got feedback from developers on this.

    Best regards,
    Adam

    Thread Starter Daniel Jimenez

    (@somosgrow)

    Hi Adam
    Thank you for your answer.
    Sure I will be patient, take the time you need.
    Again, thanks for your help.

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @somosgrow,

    We have further queries regarding your setup to check what could be advised. Since the available hours listed are from 11 pm to 4 am. Which seems to be counted as two days; suppose a user selects 4 AM, then could we know how it’s determined as the next day on your side?

    Are you also using any date fields where users could also choose the date along with these times?

    Asking specifically because then it’ll require checking if tomorrow’s date is selected, then the time accepted should be before 4 AM and after 11 PM etc.

    If you already have a form configured, is it possible to share the form export to help us better understand your setup?

    Please check the following doc on how to export a form:
    https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export

    If you are concerned about any sensitive information in the form, then you can duplicate your form, remove any sensitive information, and then export it.

    You can share the export file via Google Drive, Dropbox or any cloud services in the next reply.

    Looking forward to your response.

    Kind Regards,
    Nithin

    Thread Starter Daniel Jimenez

    (@somosgrow)

    Hi @wpmudevsupport11
    Thanks for your answer.
    I will respond all of your questions.
    1. I am using a date field in which people can select the event day. So that would be the way we know how it’s determined as the next day on our side.
    Here’s a screenshot with a preview of the form: https://prnt.sc/ug6TJ3OmzeAU
    2. Sure, I can share the form export. Is in this link:
    https://drive.google.com/file/d/14LJdWkZQxkRGQ7GT3tgfaGR4Yz2VgTAJ/view

    I really appreciate your help.

    Have a great day.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @somosgrow

    Thank you for update!

    I’ve shared you response along with the form with our developers.

    Please “stay tuned” for feedback/solution or additional questions (in case our developers still needed more information).

    Best regards,
    Adam

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    HI @somosgrow,

    Could you please try this snippet and then check whether it works fine?

    <?php
    
    add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) {
    	// Add your form IDs here.
    	$form_ids = array( 3752 );	 
    	if ( in_array( intval( $form_id ), $form_ids, true ) ) {
    		$submitted_fields = wp_list_pluck( $field_data_array, 'value', 'name' );
    		if ( !empty( $submitted_fields['time-1']['hours'] ) ) {
    			$hours 			= sprintf("%02d", $submitted_fields['time-1']['hours']);
    			$minutes 		= sprintf("%02d", $submitted_fields['time-1']['minutes']);
    			$submit_time 	= $submitted_fields['date-1'].' ' .$hours.':'.$minutes;
    
    			$now = new Datetime( $submit_time );
    			$start_time = $submitted_fields['date-1'].' 23:00';
    			$ends_time 	= $submitted_fields['date-1'].' 04:00';
    			$begintime 	= new DateTime( $start_time );
    			
    			$endtime 	= new DateTime( $ends_time );
    			$same_time 	= $endtime->format('U');
    			$endtime->modify('+1 day');
    			
    			$end_time 	= $endtime->format('U');
    			$begin_time = $begintime->format('U');
    			$now_time 	= $now->format('U');
    
    			if ( $now_time > $same_time && $now_time < $begin_time ) {
    				$submit_errors[]['time-1-hours'] = 'Selected time is not in the range';
    			}
    		}
    	}
    	return $submit_errors;
    },15,3);

    In the above snippet you’ll need to change the following line to your Form ID ie From:

    	$form_ids = array( 3752 );	 
    

    Suppose your from ID is 123 then the above line will change to:

    	$form_ids = array( 123 );	 
    

    You can implement the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Kind Regards,
    Nithin

    Thread Starter Daniel Jimenez

    (@somosgrow)

    Hello @wpmudev-support8
    I have added the code snippet following your recomendations, but I want to know, once this code was added, what the behavior of the form is supposed to be?
    Do I have to modify something in the form dashboard?
    Than you for your response.

    Best Regards,
    Daniel.

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @somosgrow

    I hope you are doing well.

    It isn’t necessary to modify anything, the behaviour should be the one you asked on:

    “1. I am using a date field in which people can select the event day. So that would be the way we know how it’s determined as the next day on our side.”

    Best Regards
    Patrick Freitas

    Thread Starter Daniel Jimenez

    (@somosgrow)

    Thanks for your answer, hoping you’re well too
    Is there any way to block the other hours on the list?
    Just let the client selects only between 11pm and 4am.
    When I try to do it on the time options it doesn’t let me apply the changes because is not a valid time limit.
    Thanks again for your help.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    HI @somosgrow

    The code that was shared with you is supposed to already do this out of the box. These lines specifically:

    $start_time = $submitted_fields['date-1'].' 23:00';
    $ends_time 	= $submitted_fields['date-1'].' 04:00';

    It wouldn’t require setting limits in field settings but you may need to change date format to 24hour format instead of AM/PM.

    If you need different hours, you would need to adjust them in those two lines of code.

    Kind regards,
    Adam

    Thread Starter Daniel Jimenez

    (@somosgrow)

    Hi @wpmudev-support8 thank you for the explanation and help you gave us.
    The form is working the way we expected.
    Great support and great plugin.

    Best regards.
    Have a great day.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Can I select the times in a timepicker from 11pm to 4am’ is closed to new replies.