1

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?

1
  • That form_alter array may not be right. IIRC, the syntax goes $form["field_qic_join"]['#default_value'] = date('Y')."-12-01"; Also, don't forget to clear caches. May 20, 2015 at 14:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.