bookmark_bordergform_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

    Current Form object.

  • $field Field Object

    Current Field object.

Examples

This example changes the max date to 2020

add_filter( 'gform_date_max_year', 'set_max_year' );
function set_max_year( $max_year ) {
    return 2020;
}

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

add_filter( 'gform_date_max_year', function ( $max_year, $form, $field ) {

    return $form['id'] == 7 && $field->id == 5 ? 2020 : $max_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()