我正在尝试分离表单字段并手动处理它们而不是使用form_widget(form)
但是遇到困难。
此部分工作正常,但我尝试对form.new_password
和form.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
,我会得到如下输出:
如果它有帮助:
供应商/ 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',
));
}
答案 0 :(得分:3)
当前密码:
{{ form_widget(form.current_password) }}
新密码:
{{ form_widget(form.new.first) }}
确认新密码:
{{ form_widget(form.new.second) }}