lundi 25 mars 2019

Symfony 4 : "Show" password when editing user

So I'm making a CRUD in my project for an entity called user, now I want the admin to edit the users information without having to change the password, but every time I try editing a user it tells me that all inputs are required. So is there anyway I can show the user's password in the field unencrypted so I can only change unless I want to.

My form:


class User1Type extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('username', TextType::class)
            ->add('plainPassword', RepeatedType::class, array(
                'type' => PasswordType::class,
                'first_options'  => array('label' => 'Password'),
                'second_options' => array('label' => 'Repeat Password'),

            ))


            ->add('active', ChoiceType::class, [
                'choices'  => [
                    'Activé' => true,
                    'Desactivé' => false,
                ],
            ])

            ->add('roles', ChoiceType::class, array(
                'attr'  =>  array('class' => 'form-control',
                'style' => 'margin:5px 0;'),
                'choices' => 
                array
                (

                        'Admin' => 'ROLE_ADMIN',

                        'Manager' => 'ROLE_MANAGER',

                        'Agent' => 'ROLE_AGENT'
,

                ) 
                ,
                'multiple' => true,
                'required' => true,
                ));

        }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => User::class,
        ));
    }
}




Aucun commentaire:

Enregistrer un commentaire