2010-07-29 27 views
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']); 

和我仍然得到“请输入一个有效的日期不工作出生“消息。我想隐藏该字段并且没有消息。

回答

2

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

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

+0

谢谢。它做到了。 – jini 2010-07-29 08:12:42