Help us understand the problem. What is going on with this article?

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

課題

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の便利機能を発掘するためには、検索キーワードの選択が重要ですね。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした