2010-07-29 28 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