trying to write a validate function within my module so that if the CCK date is not specified it will automatically put in the current date. CCK Date fields do not give the option of specifying a default value, and this field is not required since it is dependent on another field in my form.

In my validate function I check to see if the field is empty (using CCK's kludgy field naming convention) and if so I try to use form_set_value() to update the field to the current date. However in doing so I get the following error:

warning: array_shift() [function.array-shift]: The argument should be an array in /www/includes/form.inc on line 849.

my code is the following:

    if (empty($form_values['field_exclusive_startdate'][0]['value'])) { 
      $myCurrentDate = date('Y-m-d');
      form_set_value($form_values['field_exclusive_startdate'][0]['value'], $myCurrentDate);
    }

I'm guessing the form_set_value has a problem with CCK's multidimensional arrays as fields, so I'm at a loss as to how I can update the field.

I also tried passing $form_values into my validate function as reference (&$form_values) and tried the following:

$form_values['field_exclusive_startdate'][0]['value'] = date('Y-m-d');

However, while it did not return an error, it did not update the form field with the date.

Any ideas on how I can update this CCK date field with a value after the user submits?

Many thanks in advance!
brian

Comments

foxtrotcharlie’s picture

I think you'd need your validation function as follows:

  function your_new_validate($form_id, $form_values, $form) {
    if (empty($form_values['field_exclusive_startdate'][0]['value'])) {
      $myCurrentDate = date('Y-m-d');
    form_set_value($form['field_exclusive_startdate'][0]['value'], $myCurrentDate);
}
  }

Charles

www.parkroad.co.za