Created
June 11, 2014 10:38
-
-
Save memememomo/307f13f39175c8f4e942 to your computer and use it in GitHub Desktop.
同じバリデーションルールでも、フィールドごとにエラーメッセージを変更する方法 ref: http://qiita.com/uchiko/items/6782b93d620636a806f4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $val = Validation::forge(); | |
| // クロージャを設定 | |
| // Validation の _validation_required メソッドを利用する | |
| $required_rule = function ($v) use ($val) { return $val->_validation_required($v); }; | |
| // テキストフォーム | |
| $val->add('name', 'お名前') | |
| ->add_rule(['required_name' => $required_rule]); | |
| $val->set_message('required_name', 'お名前を入力してください。'); | |
| // セレクトボックス | |
| $val->add('pref', '都道府県') | |
| ->add_rule(['required_pref' => $required_rule]); | |
| $val->set_message('required_pref', '都道府県を選択してください。'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment