I have a date field that needs an unusual default date: fixed day and month, but year=thisyear. That's outside the standard default date options.
I didn't want to write a custom module for one form field, so I tried this in template.php
function secta_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'qic-node-form') { // form to make a new QIC entry
$QICdefault= date('Y')."-12-01";
$form["field_qic_join"]["und"][0]['#default_value']['value'] = $QICdefault; // set the default join date to YYYY-12-01
} // This is in template.php so will only show if form is displayed using the theme template
}
But there is no sign of the form field default changing. :-( What am I missing?
$form["field_qic_join"]['#default_value'] = date('Y')."-12-01";
Also, don't forget to clear caches.