在 Symfony2 中显示重复的字段类型
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(),
)
))
在 twig 中,我习惯这样显示这个字段:
{% 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'} }) }}
/.../
其中:
The names first and second are the default names for the two sub-fields. However, these names can be controlled via the first_name and second_name options. If you've set these options, then use those values instead of first and second when rendering.
我在 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(),
)
))
在 twig 中,我习惯这样显示这个字段:
{% 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'} }) }}
/.../
其中:
The names first and second are the default names for the two sub-fields. However, these names can be controlled via the first_name and second_name options. If you've set these options, then use those values instead of first and second when rendering.