Hi I'm trying to set a #default_value for a field which is not accessible ie: #access => FALSE

$form['date'] = array(
  '#type' => 'date_popup',
  '#title' => t('Date'),
  '#access' => FALSE,
  '#default_value' => '2009-06-18 04:31:00',
  '#date_format' => 'Y-m-d H:i:s',
);

But the value ($node->date) I get on hook_insert or hook_update is something like '0009-06-18 04:31:00' or '1009-06-18 04:31:00', notice the first number changed. I ran it through a debugger and found out this, comment on the code

function _form_set_value(&$form_values, $form_item, $parents, $value) {
  $parent = array_shift($parents);
  if (empty($parents)) {
    // here $form_values = '2009-06-18 04:31:00', $parent = 'date', $value = '18/06/2009'
    // thus it's setting $form_values['date'] = '18/06/2009';
    // i don't know where the bug is though
    $form_values[$parent] = $value; 
  }
  else {
    if (!isset($form_values[$parent])) {
      $form_values[$parent] = array();
    }
    _form_set_value($form_values[$parent], $form_item, $parents, $value);
  }
}
CommentFileSizeAuthor
#1 date.patch775 bytesariflukito
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ariflukito’s picture

FileSize
775 bytes

temporary fix
maybe the better fix is by unsetting the element value first on form process and reconstruct the element value from its sub element values.

rconstantine’s picture

I'm having the same issue. I can't seem to figure out how to set the default value. I'll check out the patch.

DamienMcKenna’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.