gform_date_max_year

Description

Use this filter to specify the maximum year displayed in the date field’s year drop down and the HTML5 max attribute for the date field’s year input.

Usage

add_filter( 'gform_date_max_year' , 'set_max_year' );

Parameters

  • $max_date string
    The maximum date to be filtered. Defaults to the current year plus one.
  • $form array
    Current form object.
  • $field array
    Current field object.

Examples

This example changes the max date to 2022.

add_filter( 'gform_date_max_year', 'set_max_year' );
function set_max_year( $max_date ) {
    return 2022;
}

This example changes the max date for a specific field on a specific form.

add_filter( 'gform_date_max_year', function ( $max_date, $form, $field ) {
    return $form['id'] == 7 && $field->id == 5 ? 2022 : $max_date;
}, 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()