【问题标题】:How to hide Date of birth field in overriden form?如何以覆盖形式隐藏出生日期字段?
【发布时间】:2010-07-29 04:07:31
【问题描述】:

在我的钩子形式alter中,这是出生日期数组:

[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']);

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

【问题讨论】:

    标签: drupal drupal-6 drupal-modules drupal-fapi


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 2011-08-22
      • 1970-01-01
      相关资源
      最近更新 更多