• Resolved itsmir

    (@itsmir)


    Hello,

    I’m looking for WordPress solution to replace an old PHP form from a static site. When completed this form generated a date + 14 days from the current date and included that date in the notification email.

    Is it possible to use formulator to do this? I was thinking by having a hidden date field front end – this would need to be pre-populated with a date +14 days from current. The hidden field then could be included in the notification mail.

    So my question is – can formulator pre-populate a date field with current+14 days?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    HI @itsmir

    I hope you’re well today!

    Forminator has “Datepicker” field built-in so it’s possible to use it this way with a little “trick”:

    1. add the “datepicker” type field to the form
    2. in field’s “Settings” tab set “Default date” to “Today”
    3. in field’s “Limits” tab set both “Start Date” and “End Date” option to “Today” with a “+” offset of “14 days”.

    Save the field and form.

    Now if you visit that form on front-end, you’ll see the date picker field with default date set to today. If you don’t make any choices in this field, the date in submission will actually be today + 14 days.

    If you try to make some choice in datepicker, you won’t be able to submit the form until you select the only date available which, in this case, will be only the “toda + 14 days” date.

    You can also hide that field entirely on front-end with a bit of CSS code like this:

    #date-1 {
    	display:none!important;
    }

    Note: if there’ll be more than one datepicker fields on the same form, you may need adjust the number 1 in this CSS to match the related field on form.

    Best regards,
    Adam

    Thread Starter itsmir

    (@itsmir)

    That sounds perfect, thanks so much – I’ll give it a try!

    Thread Starter itsmir

    (@itsmir)

    Hello,

    This almost works!

    When the datepicker was hidden the form gives a “Error: Your form is not valid, please fix the errors!” but shows no error. So I un-hid the datepicker and it error’s because it needs a date to be selected (& today’s date is not allowed). Tapping on the datepicker field, I can select only the +14 days date and the form can be submitted.

    You said above ” ..if you visit that form on front-end, you’ll see the date picker field with default date set to today. If you don’t make any choices in this field, the date in submission will actually be today + 14 days”. Which is just what I need – did I miss something ?? We want the field hidden & no choice to have to be made.

    The form on our staging site is here with the offending date field (Return Date) un-hidden: https://awdentalstudio.com/staging/pl-ticket/ (notifications disabled)

    Thanks in advance
    Miriam

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @itsmir

    I hope you are doing well.

    This actually sounds a possible bug and not expected behaviour, I was able to replicate it on my lab site and pinged our developers to verify if we can make the + 14 days as default selected.

    We will keep you posted.
    Best Regards
    Patrick Freitas

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @itsmir,

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

    <?php
    
    add_action( 'wp_footer', 'wpmudev_autoset_date', 9999 );
    function wpmudev_autoset_date() {
    	global $post;
        if ( is_a( $post, 'WP_Post' ) && !has_shortcode( $post->post_content, 'forminator_form' ) ) {
            return;
        }
    	?>
    	<script type="text/javascript">
    	jQuery(document).ready(function($){
    		setTimeout(function() {
    			$('.forminator-custom-form').trigger('after.load.forminator');
    		},100);
    
    		$(document).on('after.load.forminator', function(e, form_id) {
    			if ( e.target.id == 'forminator-module-2910' ) {
    				var next_date = $('#date-1 input').datepicker('getDate');
    				next_date.setDate(next_date.getDate() + 14);
    				$('#date-1 input').datepicker('setDate', next_date);
    			}
    		});
    	});
    	</script>
    	<?php
    }

    You’ll need to update the above Snippet in the following line with your form ID, ie:

    			if ( e.target.id == 'forminator-module-2910' ) {
    	

    Suppose the form ID is 123, then the above line will change to:

    			if ( e.target.id == 'forminator-module-123' ) {
    	

    You can add the 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 itsmir

    (@itsmir)

    Hello Nithin,

    I tried the above code (after updating the form id, field id & changed the 14 to 10 (customer changed requirements) and still getting the same results πŸ™ so not working.

    I tested with date field limits off & on – also doesn’t make a difference with this code.

    If you need admin access to take a look around please let me know.
    Thanks,
    Miriam

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @itsmir,

    Could you please share the form export so that we can give a closer look at this?

    Also, if possible, please attach the full code you have applied on your website so that we can have a better idea of what might have been missed.

    You can use Google Drive, Dropbox or any such cloud services to share the export and code in the next reply.

    Looking forward to your response.

    Kind Regards,
    Nithin

    Thread Starter itsmir

    (@itsmir)

    Sure. The folder here

    https://drive.google.com/drive/folders/1HB9R7M1_ZQ0K_4DEFikzZzjbVb2z1uTC?usp=share_link

    includes:
    form export
    custom css
    mu-plugin (forminator-return-date-fix.php)
    WP site info

    If you need any further info pls let me know. Thank you for your help!

    Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @itsmir

    Thanks for response and sharing the form.

    Getting a step back: when I suggested solution with setting limits in datepicker field I actually tested it on my setup before posting and it seemed to work fine. But I’ve tested your form now and I can confirm that it’s not working as expected.

    So I did some more testing and it seems that I wasn’t right – it appeared to be working for me but on a very simple form with only a single datepicker and I actually made a mistake during testing. I sincerely apologize for that!

    —–

    As for the solution, please keep the form as is and make sure that the code that was shared is still there (mu plugin) and then go to form’s “Behavior” settings and switch of “Load form using AJAX” option under “Rendering” section.

    Then update the form and clear all cache on site/server and check it again. It should be working then but please double-check it.

    Kind regards,
    Adam

    Thread Starter itsmir

    (@itsmir)

    Woohoo – that date now prepopulates correctly.

    However it has generated a new issue with the date-picker calendar rendering now below the footer on page load. This disappears once one of the 2 date fields is tapped and appears correctly dropped down from date field – odd!

    https://awdentalstudio.com/staging/patient-lab-ticket-form-2/

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @itsmir

    Sorry to hear it, can you please try this CSS in WordPress > Appearance > Customise > Additional CSS:

    .page-id-1569 #ui-datepicker-div{
        display: none;
    }

    Let us know the result you got,
    Best Regards
    Patrick Freitas

    Thread Starter itsmir

    (@itsmir)

    Super – that’s done the trick!!

    Thank you so much for all your help getting this form just how the client wants it. It’s much appreciated.

    Regards,
    Miriam

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @itsmir,

    Glad to hear it’s sorted; feel free to mark this thread as resolved if you don’t have any further queries.

    If you have a moment, we would greatly appreciate it if you could rate our plugin quickly.

    This will help us keep the plugin available for free.
    https://wordpress.org/support/plugin/forminator/reviews/#new-post

    Regards,
    Nithin

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Autofill/Limit date in date field’ is closed to new replies.