在Drupal中设置复选框的默认值

时间:2011-12-29 08:52:20

标签: forms checkbox drupal-7

我正在尝试在我的D7表单上设置#default_value,但它不起作用......这是我的阵列:

'thema_30fdc789-1453-4efa-93d6-123cab52206e' => 
    array
      '#type' => string 'checkboxes' (length=10)
      '#title' => string 'What kind of fiches??' (length=42)
      '#options' => 
        array
          'create' => string 'New fiches'     (length=13)
          'update' => string 'Updated fiches' (length=13)
          'delete' => string 'Deleted fiches' (length=13)

使用以下行编辑此表单后:

$form['thema_30fdc789-1453-4efa-93d6-123cab52206e']['#default_values']= 
        array('create' => 'Nieuwe fiches', 'update' => 'Update fiches', 'delete' => 'Delete fiches');

我得到了var_dump

 'thema_30fdc789-1453-4efa-93d6-123cab52206e' => 
    array
      '#type' => string 'checkboxes' (length=10)
      '#title' => string 'What kind of fiches??' (length=42)
      '#options' => 
        array
          'create' => string 'Newfiches'      (length=13)
          'update' => string 'Updated fiches' (length=13)
          'delete' => string 'Deleted fiches' (length=13)
      '#default_values' => 
        array
          'create' => string 'Newfiches'      (length=13)
          'update' => string 'Updated fiches' (length=13)
          'delete' => string 'Deleted fiches' (length=13)

所以,hook_form_alter完成了他的工作。然而,重新加载页面时没有选中复选框...我需要做些什么来确保它们已被检查?

1 个答案:

答案 0 :(得分:1)

没关系。我自己找到了。我需要将字符串调整为:

$form['thema_30fdc789-1453-4efa-93d6-123cab52206e']['#default_value'] = array('create', 'update','delete');