LoginSignup
0
0

More than 3 years have passed since last update.

Symfony4.4 パスワード変更フォームでパスワードの確認エリアを作成する

Posted at

課題

Symfonyのフォームで、以下のようなパスワードを設定する場合に、再度パスワードを入力させる確認用のテキストフィールドを作りたい。

image.png

TL;DR

ずばり、フォームタイプとして、RepeatedType Fieldが用意されている。

これは指定するフォームタイプ。例えば、テキストフィールドとか、パスワードフィールドを2つ用意してくれる。

ちょうどサンプルがそのまんま使えてしまう。

use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
// ...

$builder->add('password', RepeatedType::class, [
    'type' => PasswordType::class,
    'invalid_message' => 'The password fields must match.',
    'options' => ['attr' => ['class' => 'password-field']],
    'required' => true,
    'first_options'  => ['label' => 'Password'],
    'second_options' => ['label' => 'Repeat Password'],
]);

感想

Symfonyの便利機能を発掘するためには、検索キーワードの選択が重要ですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0