2013-11-01 53 views
0

我目前使用Silex2 FormFactory來建立一個窗體,我偶然發現了一個問題。Silex雙表格

我有一個登錄頁面(login.twig),要求輸入電子郵件和密碼。此表格包含驗證。但我希望這個登錄表單總是在我的標題中(在我的layout.twig上)。我創建了表單並將該操作鏈接到了登錄頁面的位置。我必須手動編寫每個輸入元素的正確ID和名稱,並且將生成的login.twig的令牌複製到表單中。但我懷疑這是做到這一點的正確方法嗎?

<form class="navbar-form pull-right" action="{{ path('auth.login') }}" method="post" novalidate="novalidate">{# disables HTML5 formchecking #} 
    <input class="span2" type="text" id="loginform_email" name="loginform[email]" placeholder="Email"> 
    <input class="span2" type="password" id="loginform_password" name="loginform[password]" placeholder="Password"> 
    <input id="loginform__token" type="hidden" value="9eb2a291d32d114987aee1548da878201dd79a7b" name="loginform[_token]"> 
    <button class="btn" type="submit">Sign in</button> 
    <a href="{{ path('auth.register') }}">register here</a> 
</form> 

回答

0

只要它們是相同形式的獨特實例,並且引用不同,它應該沒問題。

但我會建議爲了可用性的原因,只需在登錄頁面上隱藏登錄表單。你可以決定你的路線的名稱,並設置它作爲一個全局變量可能:

$app->before(function (Request $request) { 
    $app['twig']->addGlobal('currentRoute', $request->get('_route')); 
}); 

然後在你的模板:

{% if currentRoute != 'auth.login') %} 
    // output your form here 
{% endif %}