Setting Default Year in CCK Field

If you use CCK often, then you've probably at least once had to implement a select box where the user can select a year value. Sometimes they're used for birthdays, magazine issues, events, or even historical reasons.

You can easily populate the "Allowed values" textarea of the field's "edit" page, but how can you quickly set the default value to the current year (and not have to worry about changing it every year)?

Luckily, its pretty easy. In the "Default value" fieldset there's a textarea where you can enter a bit of PHP code. Enter the following and you're good to go:

return array(
0 => array('value' => date('Y')),

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!