I have build a form class to generate a form that will allow a user to type in a new password twice in order to change it.
code:
<?php
namespace UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\CallbackValidator;
class PasswordType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('password', null);
$builder->add('confirmPassword', null, array('label' => 'Confirm Password', 'property_path' => false));
$builder->addValidator(new CallbackValidator(function($form)
{
if($form['confirmPassword']->getData() != $form['password']->getData()) {
$form['confirmPassword']->addError(new FormError('Passwords must match.'));
}
}));
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'UserBundle\Entity\User',
);
}
public function getName()
{
return 'password';
}
}
Now, this class works pretty well, BUT my issues is that when I set the first password field to type "password" I get this error:
Circular reference detected in the "password" type (defined in class "UserBundle\Form\Type\PasswordType").
And I cannot leave it set to "null" as it will use a normal text input field, which is not ideal.
Any ideas folks?