Vincent DUPONT
Vincent DUPONT

Reputation: 71

Show * characters on PasswordType Field

I need to show "*" characters on a PasswordType Field (or TextType Field) instead of the clear password for editing a user.

This field is saved on a DB, this is important that only the display change.

For example:

Actual: Actual display Expected :Expected display

I don't find anything about that in the official documentation.

UP:

Code of the VisiteurType.php:

 public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
        ->add('nom', TextType::class)
        ->add('prenom', TextType::class)
        ->add('login', TextType::class)
        ->add('mdp', PasswordType::class, array('always_empty' => false))
            [etc.]
    }

Code of the form.html.twig:

   <div class="password-type">
            {{ form_label(visiteurForm.mdp, null, { 'label_attr':  {
                'class': 'col-sm-4 control-label'
            }}) }}
            <div class="col-sm-6">
                {{ form_errors(visiteurForm.mdp) }}
                {{ form_widget(visiteurForm.mdp, { 'attr':  {
                    'class': 'form-control',
                    'rows': '8'
                }}) }}
            </div>
        </div>

It broke my design: Broken design

Upvotes: 1

Views: 1226

Answers (1)

shivam
shivam

Reputation: 491

You can use

<input type="password" id="password"></input>

by type ="password" it will show "*" instead of text value

Upvotes: 1

Related Questions