Description
Use this filter to specify the minimum year displayed in the date field’s year drop down 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
Current form object. - $field array
Current field object.
Examples
This example changes the minimum date to 1900.
add_filter( 'gform_date_min_year', 'set_min_year' );
function set_min_year( $min_year ) {
return 1900;
}
This example changes the min date for a specific field on a specific form.
add_filter( 'gform_date_min_year', function ( $min_year, $form, $field ) {
return $form['id'] == 7 && $field->id == 5 ? 2014 : $min_year;
}, 10, 3 );
Placement
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()