[support] Default Value for Form

Fred Jones fredthejonester at gmail.com
Thu Jul 28 11:45:07 UTC 2011


I have a form in D6 with a date field which should be set to the first
day of this month when the form first loads, but if the user submits
the form, it should come back with the same value he set.

I can not get the initial setting part to work however. :(

I tried:

function _fred_general_report($form_state=NULL) {
 if(!isset($form_state['values']['start_date'])) {
    $form_values['values']['start_date']['year'] = date('Y');
    $form_values['values']['start_date']['day'] = 1;
    $form_values['values']['start_date']['month'] = date('n');
  }
  $form['start_date'] = array (
    '#type' => 'date',
    '#title' => 'Start Date',
    '#value' => $form_state['values']['start_date']
  );

and I now have:

function _fred_general_report($form_state=NULL) {
    $x['values']['start_date']['year'] = date('Y');
    $x['values']['start_date']['day'] = 1;
    $x['values']['start_date']['month'] = date('n');
  $form['start_date'] = array (
    '#type' => 'date',
    '#title' => 'Start Date',
    '#value' => $form_state['values']['start_date'],
    '#default_value' => $x['values']['start_date']
  );

but it's not working.

Can anyone tell me what I am doing wrong?

Thanks.


More information about the support mailing list