[英]Display repeated field type in Symfony2
我在Symfony2表單中有一個重復的密碼字段類型,如下所示:
->add('password', 'repeated', array(
'type' => 'password',
'invalid_message' => 'Les mots de passe doivent correspondre',
'options' => array('required' => true),
'first_options' => array('label' => 'Mot de passe'),
'second_options' => array('label' => 'Mot de passe (validation)'),
'required' => $bRequired,
'trim' => true,
'constraints' => array(
new Assert\Regex(array(
'pattern' => "/^(?=.*[0-9])(?=.*[a-z])[a-zA-Z0-9!?+]{8,15}$/",
'match' => true,
'message' => "msg"
)),
new Constraints\NotBlank(),
)
))
在樹枝中,我習慣於顯示如下字段:
{% for passwordField in form.password %}
{{ form_row(passwordField,{'attr': { 'class': 'form-control'} }) }}
{% endfor %}
我不知道是否有單獨顯示密碼字段和確認字段,所以我可以在我的形式不同的地方顯示出來的一種方式。
如文檔中所述:
// in your template.html.twig
/.../
{{ form_row(form.password.first,{'attr': { 'class': 'form-control'} }) }}
{{ form_row(form.password.second,{'attr': { 'class': 'form-control'} }) }}
/.../
哪里:
名字first和second是兩個子字段的默認名稱。 但是,可以通過first_name和second_name選項控制這些名稱。 如果設置了這些選項,則在渲染時使用這些值而不是第一和第二。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.