LoginSignup
4
4

More than 5 years have passed since last update.

パスワードとパスワード確認をValidationでやる方法

Last updated at Posted at 2015-03-16

はじめまして、FuelPHP 初心者のMakotoです。以前、CodeIgniter を利用していましたが、会社の方針で FuelPHP を使うことになりました。

MVCの構造等は、ある程度理解しているので苦労はなかったのですが、Validation部分ではまったので、そのメモを書いておきます。

FuelPHPでパスワードとパスワード確認をValidationでやる方法

FuelPHPのValidationにクロージャを使う - Qiita を参考に、組みました。たぶん、こんな形で良いんだよね!?


$val = Validation::forge();

$password = Input::post('password');
$confirm_password = Input::post('confirm_password');

$val->add('password', 'パスワード')
    ->add_rule('trim')
    ->add_rule('required')
    ->add_rule('min_length', 8)
    ->add_rule('max_length', 16)
    ->add_rule(
        function($password) use ($confirm_password) {
            if ($password === $confirm_password) {
                return true;
            } else {
                Validation::active()->set_message('closure', 'パスワードと確認の値が異なりました。');
                return false;
            }
        });

検索したけど、結構出てこない感じだったので貼っておきます。

参考になればー!

4
4
1

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
4
4