手动分隔表单字段而不是使用form_widget(表单)

时间:2014-09-29 10:12:19

标签: symfony twig fosuserbundle

我正在尝试分离表单字段并手动处理它们而不是使用form_widget(form)但是遇到困难。

此部分工作正常,但我尝试对form.new_passwordform.new_password_confirmation做同样的事情我收到错误说Method "form.new_password" for object .... doesn't exist in FOSUserBundle....等等。我唯一可以将它用于form.plainPassword并不能解决问题。

任何人都知道如何分隔字段并显示它们吗?

这很好:

<tr>
    <td>{{ form_label(form.current_password }}</td>
    <td>{{ form_widget(form.current_password }}
        <p>{{ form_errors(form.current_password) }}</p></td>
</tr>

无效:

<tr>
    <td>{{ form_label(form.new_password }}</td>
    <td>{{ form_widget(form.new_password }}
        <p>{{ form_errors(form.new_password) }}</p></td>
</tr>
<tr>
    <td>{{ form_label(form.new_password_confirmation }}</td>
    <td>{{ form_widget(form.new_password_confirmation }}
        <p>{{ form_errors(form.new_password_confirmation) }}</p></td>
</tr>

如果我使用form.plainPassword,我会得到如下输出:

enter image description here

如果它有帮助:

供应商/ friendsofsymfony /用户束/ FOS / UserBundle /窗体/类型/ ResettingFormType.php

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('plainPassword', 'repeated', array(
        'type' => 'password',
        'options' => array('translation_domain' => 'FOSUserBundle'),
        'first_options' => array('label' => 'form.new_password'),
        'second_options' => array('label' => 'form.new_password_confirmation'),
        'invalid_message' => 'fos_user.password.mismatch',
    ));
}

供应商/ friendsofsymfony /用户束/ FOS / UserBundle /窗体/类型/ ChangePasswordFormType.php

public function buildForm(FormBuilderInterface $builder, array $options)
{
    if (class_exists('Symfony\Component\Security\Core\Validator\Constraints\UserPassword')) {
        $constraint = new UserPassword();
    } else {
        // Symfony 2.1 support with the old constraint class
        $constraint = new OldUserPassword();
    }

    $builder->add('current_password', 'password', array(
        'label' => 'form.current_password',
        'translation_domain' => 'FOSUserBundle',
        'mapped' => false,
        'constraints' => $constraint,
    ));
    $builder->add('plainPassword', 'repeated', array(
        'type' => 'password',
        'options' => array('translation_domain' => 'FOSUserBundle'),
        'first_options' => array('label' => 'form.new_password'),
        'second_options' => array('label' => 'form.new_password_confirmation'),
        'invalid_message' => 'fos_user.password.mismatch',
    ));
}

1 个答案:

答案 0 :(得分:3)

当前密码:

{{ form_widget(form.current_password) }}

新密码:

{{ form_widget(form.new.first) }}

确认新密码:

{{ form_widget(form.new.second) }}