2014-09-26 46 views
0

有人會知道下面的問題的解決方案嗎?當模板發生變化時,Symfony不會顯示錶單提交錯誤

注意:Symfony頁腳信息欄(profiler)有錯誤,系統會捕獲它們。下面的模板被記錄到FOSUserBundle。

當我使用這個(原)編輯頁面,我可以看到在頁面表單驗證錯誤:

<form action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit"> 
     {{ form_widget(form) }} 
     <div> 
      <input type="submit" value="{{ 'profile.edit.submit'|trans }}" /> 
     </div> 
    </form> 

當我使用這個(修改)之一,我無法看到表單驗證錯誤頁面:

<form action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit"> 
    <div>{{ form_errors(form) }}</div> 

    <table> 
     <tr> 
      <td>Username</td> 
      <td>{{ form_widget(form.username) }}</td> 
     </tr> 
     <tr> 
      <td>Email</td> 
      <td>{{ form_widget(form.email) }}</td> 
     </tr> 
     <tr> 
      <td>Current Password</td> 
      <td>{{ form_widget(form.current_password) }}</td> 
     </tr> 
    </table> 
    {{ form_widget(form._token) }} 
    <input type="submit" value="{{ 'profile.edit.submit'|trans }}" /> 
</form> 

回答

2

您可以嘗試在你的形式設置error_bubbling。按照documentation

If true, any errors for this field will be passed to the parent field or form. For example, if set to true on a normal field, any errors for that field will be attached to the main form, not to the specific field.

所以如果error_bubbling設置爲false(默認),你應該顯示如特定字段的錯誤消息:

<tr> 
    <td>Username</td> 
    <td>{{ form_widget(form.username) }}</td> 
    <td>{{ form_errors(form.username) }}</td> 
</tr> 
+0

我會檢查它在星期一和我相信這將解決我以前使用它的問題,但由於某種原因,大腦會耗盡汁液的時間! – BentCoder 2014-09-26 18:07:33

相關問題