• Resolved sjkd

    (@sjkd)


    Hello there support,

    I was wondering if there is a solution to this:

    I want to add the datepicker field twice to let my visitor pick a date for arrival and one for departure. When he for example chooses Sep. 20 for arrival I would love the second datepicker to automatically switch to the month of september too so he can pick a further date – does this make sense? Do you know what I am trying to achieve?

    Thank you very much in advance!
    Stephi

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @sjkd,

    I am afraid, this isn’t possible with Forminator out of the box. However, a similar custom code as follows can help with this.

    add_action( 'wp_footer', function(){
    	?>
    	<script>
    		(function($){
    			$(function(){
    				let _form = $('#forminator-module-8');
    				if( _form.length ){
    					_form.find('[name="date-1"]').on('change', function(){
    						let _value = $(this).val();
    						if( _value ){
    							let _date_picker = _form.find('[name="date-2"]').data('forminatorFrontDatePicker');
    							if( _date_picker ){
    								_date_picker.$el.datepicker('option','defaultDate', _value);
    							}
    						}
    					});
    				}
    			});
    		})(window.jQuery)
    	</script>
    	<?php
    }, 21 );

    Please note, you need to change the forminator-module-8 and name attribute of the select field in the above code according to your form fields.

    Kind Regards,
    Nebu John

    Thread Starter sjkd

    (@sjkd)

    Hello Nebu,

    thank you very much for your time & help.

    I’m afraid I am too noody to understand what attributes I have to change exactly. Can you hand me some more detailed help?

    Thank you VERY MUCH in advance!

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @sjkd

    I hope you are doing well.

    The attributes are the:

    [name="date-1"] & [name="date-2"]

    You can find more about attributes on :
    https://www.w3schools.com/html/html_attributes.asp

    In case you still have doubt, can you please export your form and share using Google drive?

    https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export

    Best Regards
    Patrick Freitas

    Thread Starter sjkd

    (@sjkd)

    Hey Patrick,

    thanks for your help. I checked on “date-1” and “date-2” and they seem to be right? But it’s still not working. Do I need to change more attributes like the form id?

    I would really appreciate your extra help with sending you the form. I hope wetransfer is okay, too? (I don’t use Google drive)

    https://we.tl/t-wQuRApZBoa

    As always: many many thanks!

    Stephi

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @sjkd

    Thank you for the form.

    I checked and the only change that it needs is indeed the form ID, the date-1 and date-2 are the same.

    Since IDs are not the same as our sites, you can edit your form and find your ID in the URL”

    https://monosnap.com/file/XinjPn58DA6XkvrfAer5RSgj62amZo

    Then update the

    #forminator-module-8

    Best Regards
    Patrick Freitas

    Thread Starter sjkd

    (@sjkd)

    Hello Patrick,

    thanks for the help how to figuring out what/ where the forms ID is.

    I tried it with #forminator-module-328 (thats the ID it shows me), #328 and 328 but none is working.

    And, whenever i refresh/ reopen the site with the code it only shows this lines:

    add_action( 'wp_footer', function(){
    	?>
    	
    	<?php
    }, 21 );

    (rest is gone)

    Am I still doing something wrong?

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @sjkd

    How are you adding the code?

    Using a plugin or as a mu-plugin?

    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Make sure to open the PHP tag too

    
    <?php
    
    add_action( 'wp_footer', function(){
    	?>
    	<script>
    ....

    Best Regards
    Patrick Freitas

    Thread Starter sjkd

    (@sjkd)

    Hallo Patrick,

    I used the code you posted first and it ends with the…. `<?php
    }, 21 );` …not closed code? Can you recheck?

    I pasted it in the forminator CSS code area? Should it be in the wordpress all over css thing?

    As always: thanks for your help and sorry about my struggle ??

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @sjkd

    Thank you for response!

    Patrick apparently didn’t share full code in his last post but only used the starting part of it to show how to add opening PHP tag. I’m sorry for causing confusion.

    It should not be added to CSS in Forminator either. It’s not a CSS code and it won’t work there, instead it would be best to use it as MU plugin.

    Let me recap it for you then, step by step. Here’s how to add the code to the site:

    1. remove it from the Forminator’s CSS code first, it shouldn’t be there

    2. create empty file on your computer, using some “clean text” editor such as Notepad++, Sublime or similar; basically any simple “text” editor and not any office-type writer.

    3. give this file a name with a .php extension, for example:

    forminator-date-connection.php

    3. in the first line of the file add this line

    <?php

    4. right below it copy and paste entire code from this post

    https://www.ads-software.com/support/topic/datepicker-connection-between-date-1-arrival-and-date-2-departure/#post-14524367

    Note: before copying the code, click on a little “expand” tab right below the code field in the post, only then you’ll see full code

    5. now you need to adjust the code to use correct fields IDs; this is explained in this post earlier

    https://www.ads-software.com/support/topic/datepicker-connection-between-date-1-arrival-and-date-2-departure/#post-14547571

    Note: still work on that file in the same simple text editor

    6. save the file

    7. upload the file using FTP or cPanel’s “File Manager” or similar tool to the “/wp-content/mu-plugins” folder of your site’s WordPress installation; if there’s no “mu-plugins” folder in “wp-content” folder, create an empty one first.

    Best regards,
    Adam

    Thread Starter sjkd

    (@sjkd)

    Thank you for all the information, Adam.

    I’ll have a try.

    Can you tell me though how i change the ID the right way?
    #forminator-module-8 = #forminator-module-328? or #328 or 328 without hash tag?

    I’m afraid I’ll trial and error a little more and would at least be happy to know i have the right code in one peace.

    This is my status now:

    <?php
    add_action( 'wp_footer', function(){
    	?>
    	<script>
    		(function($){
    			$(function(){
    				let _form = $('#forminator-module-8');
    				if( _form.length ){
    					_form.find('[name="date-1"]').on('change', function(){
    						let _value = $(this).val();
    						if( _value ){
    							let _date_picker = _form.find('[name="date-2"]').data('forminatorFrontDatePicker');
    							if( _date_picker ){
    								_date_picker.$el.datepicker('option','defaultDate', _value);
    							}
    						}
    					});
    				}
    			});
    		})(window.jQuery)
    	</script>
    	<?php
    }, 21 );

    What is the 21 for?

    Thanks in advance! I really appreciate your effort and help!

    Plugin Support Predrag – WPMU DEV Support

    (@wpmudev-support1)

    Hi @sjkd,

    The ID is supposed to look exactly like in the code, just change the 8 with the 328 our your desired ID.
    So this:
    let _form = $('#forminator-module-8');
    Should be changed to this:
    let _form = $('#forminator-module-328');

    21 is just for setting it to fire the a bit later rather than at start of the load.

    Cheers.
    Predrag

    Thread Starter sjkd

    (@sjkd)

    Hello Predrag,

    thanks for the help. I followed all you guys instructions step by step and it’s still not working. Do you have an idea what the issue might be?

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @sjkd

    Is it possible to send the Form URL and we can test the code in our browser to confirm if anything is wrong?

    Best Regards
    Patrick Freitas

    Thread Starter sjkd

    (@sjkd)

    Hey Patrick,

    of course! I would appreciate it!

    –> https://www.landhaus-bolzum.com/#kontakt

    The website’s language is in german – hope you don’t mind.

    Ongoing thanks for all your help!
    Can’t wait to hear from you again.

    Stephi

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @sjkd,

    Thank you for sharing the URL, the form ID and name attribute of date fields are the same as you have mentioned. We would like to verify the code that you have added in the mu-plugin, can you please share it? Please use any cloud platform like Google Drive or DropBox to share the file (make sure the URL is publically accessible).

    Please also let us know the exact path where you have added the mu-plugin.

    Kind Regards,
    Nebu John

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Datepicker / Connection between date 1 (arrival) and date 2 (departure)’ is closed to new replies.