The gform_date_min_year filter allows you to set the minimum year displayed in the date field’s year drop-down list and the HTML5 min attribute for the date field’s year input.
Usage
add_filter('gform_date_min_year', 'set_min_year');
Parameters
$min_year
(string) – The minimum date to be filtered. Defaults to 1920.$form
(array) – The current form object.$field
(array) – The current field object.
More information
See Gravity Forms Docs: gform_date_min_year
Examples
Set minimum year to 1900
This example sets the minimum date to 1900.
add_filter('gform_date_min_year', 'set_min_year'); function set_min_year($min_year) { return 1900; }
Set minimum year for a specific field on a specific form
This example sets the minimum year for field ID 5 on form ID 7 to 2014.
add_filter('gform_date_min_year', function($min_year, $form, $field) { return $form['id'] == 7 && $field->id == 5 ? 2014 : $min_year; }, 10, 3);
Note: This code should be placed in the functions.php
file of your active theme.
Source Code: This filter is located in the following methods in includes/fields/class-gf-field-date.php
:
- GF_Field_Date::get_field_input()
- GF_Field_Date::get_year_dropdown()