2012-03-02 30 views
1
//-- this is my controller code------ 

$form = $this->createFormBuilder() 
       ->add('curpass', 'password') 
       ->add('password', 'repeated', array(
        'type' => 'password', 
        'first_name' => " new Password", 
        'second_name' => "Re-enter Password", 
        'invalid_message' => 'The password fields must match.' 
       )) 
       ->getForm(); 

//----this is my twig code----- 

<form action="#" method="post" {{ form_enctype(form) }}> 
    {{ form_widget(form) }} 

    <input type="submit" /> 
</form>  

你能告訴我我的代碼有什麼問題嗎?它不會比較密碼字段'新密碼'和'重新輸入密碼'。在symfony2中無法驗證的重複字段

+0

它打印什麼? – meze 2012-03-02 07:56:01

回答

0

已經在documentation讀:

這是用於第一個字段的實際字段名。然而,由於輸入到 這兩個字段中的實際數據將在分配給重複的 字段本身(例如密碼)的密鑰下可用,所以這大多是無意義的。但是,如果您未指定標籤,則此字段名稱用於爲您「猜測」標籤。

這意味着您不能使用first_name和second_name設置標籤,但必須使用選項並將數組與標籤一起傳遞。我沒有找到任何解決方案來更改第二個字段的標籤。

嘗試刪除first_name和second_name並查看它是否有效。

+1

必須解決這個問題嗎?我也有同樣的問題。 – gremo 2012-03-22 22:07:22