Dieses Blog durchsuchen

Samstag, 16. Juli 2016

symfony3 : add password confirmation field to a password field

in most of the cases its a good idea to let the user confirm is password to prevent uneeded password support.

symfony2 has an own PasswordType in his formpackage.

Include the needed namespaces:
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;

add the PassWordType to your form

<?php
namespace Check\BlogBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username')
->add('email', EmailType::class,array('empty_data' => null))
->add('password',RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password')))
->add('firstname')
->add('lastname')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Check\BlogBundle\Entity\User'
));
}
public function getBlockPrefix()
{
return 'check_blogbundle_user';
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

Keine Kommentare:

Kommentar veröffentlichen