2

在我的钩子表单中,这是出生日期数组:

[Birthdate] => Array(
  [#type] => fieldset
  [#title] => Birthdate
  [#weight] => 1
  [profile_birthdate] => Array(
    [#type] => date
    [#title] => Birthdate
    [#default_value] =>
    [#description] => The content of this field is kept private and will not be shown publicly.
    [#required] => 1
  )
)

我试过了:

unset($form['Birthdate']['profile_birthdate']);
     unset($form['Birthdate']);

这不起作用,因为我仍然收到“请输入有效的出生日期”消息。我希望隐藏该字段并且没有消息。

4

1 回答 1

2

错误消息的措辞('...有效日期...')暗示这是从表单验证功能发出的。根据其编写方式,它可能仍会尝试验证该字段,即使您已从表单中成功删除它。

如果是这种情况,您将需要使用不需要出生日期字段的自定义版本覆盖验证功能(检查$form['#validate']您的hook_form_alter()实现中的内容)。或者,您可以将其转换为'#type' => 'hidden'or '#type' => 'value',而不是删除该字段,并提供一个通过验证的默认值,但是您最终会分配虚假的出生日期,这可能不是您想要的。

于 2010-07-29T06:46:40.093 回答