Jump to content

Set the minimum date for the second date field


Recommended Posts

Hi All,
I'm really hoping someone can help me as i'm sure there's quite a simple solution to this.
I'm building a form in Wordpress using a form builder plugin. The form has several date fields that clients need to fill in to tell us when they will be sending us print files and then a 2nd set of fields for when they need to be sent back.
I've found some code on the plugin devs website that shows me how to set the 2nd date to be XX number of days after the 1st date but it only works if you have 2 date fields in your form.
I currently have about 40 so i need to know how to extend this code to include more date fields.
Here is the code the plugin dev supplied:

add_action('frm_date_field_js', 'start_and_end_dates', 10, 2);
function start_and_end_dates($field_id, $options){
    $key_one = 'pickup';// Change pickup to the KEY of the first date field
    $key_two = 'dropoff';// Change dropoff to the KEY of the second date field
    $days_between = 0;// Change 0 to the number of days that should be between the start and end dates

    if ( $field_id == 'field_'. $key_one ) {
        echo ',beforeShowDay: function(dateOne){var secondDate=$("#field_' . $key_two . '").datepicker("getDate");if(secondDate==null){return[true];}var modDate=new Date(secondDate);modDate.setDate(modDate.getDate()-' . $days_between . '+1);return [(dateOne < modDate)];}';
    } else if ( $field_id == 'field_' . $key_two ) {
        echo ',beforeShowDay: function(dateTwo){var firstDate=$("#field_' . $key_one . '").datepicker("getDate");if(firstDate==null){return[true];}var modDate=new Date(firstDate);modDate.setDate(modDate.getDate() + ' . $days_between . '-1);return [(dateTwo > modDate)];}';
    } else {
        echo ',beforeShowDay: null';

So in effect all i need to do is find out how to extend this to add more date fields.


Any help would be amazing as i'm very new at this and know very little about coding.




Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.