[support] Default Value for Form

Ms. Nancy Wichmann nan_wich at bellsouth.net
Thu Jul 28 13:51:52 UTC 2011


#value is what you will get back and cannot be changed. I suspect you really want only #default_value.

Nancy
 
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.

From: Fred Jones
>
>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.
>-- 
>[ Drupal support list | http://lists.drupal.org/ ]
>
>
>


More information about the support mailing list