Gravity Forms is quite possibly the best forms plugin available for WordPress, but even with the vast array of functionality it offers right out of the box it still has its limitations.

One such limitation is the date picker field, offers practically no chance of configuration.

Recently a client asked to have their date picker so it would only select dates in the future, and while Gravity Forms has no way of doing this, fortunately there’s an easy jQuery fix, since Gravity forms uses jQuery standard date picker.

Simply add the following script code to your page/page template before where the form appears, substituting the #input_1_10 part with the form field ID of the datepicker field ID on your form.

<script type=”text/javascript”>
jQuery.noConflict();
jQuery(document).ready(function($) {
$( “#input_1_10” ).datepicker({ minDate: ‘+0d’ });
});
</script>

To set the form to select dates that appear further in the future or perhaps only a week previous, change the +0d (plus zero days) part to something suited to your particular requirements (i.e. +14d to only allow dates two weeks in the future).

Update

Since I wrote this article, Gravity forms has updated their hooks so there are other ways to implement this. Add the following to your theme’s functions.php and it should restrict the date selection and block off future dates. Ensure you change the field ID in the code to match your form field’s ID.

gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
    // Apply to field 2 only 
    if ( fieldId == 2 ) {
        optionsObj.minDate = 0;
    }
    return optionsObj;
});