I want password repeat field in my web-application based on Yii when create and update user. When create I want both fields to be required and when update, user can left these fields empty(password will be the same) or enter new password and confirm it. How can I dot it?
相关问题
- How can I implement password recovery in an iPhone
- How can I set the SVN password with Emacs 23.1 bui
- Yii - Eliminate default controller ID for a module
- how to change csrf field id from YII_CSRF_TOKEN to
- Load balancing with Yii sessions
相关文章
- Can you run console jobs from yii2-basic?
- How to do a bulk database insert in Yii2?
- TeamCity Username / password
- rails 3, how add a simple confirmation dialog when
- Yii2 - check if the user is logged in view
- Call static method from a string name in PHP
- radioButtonList checked by default
- Postgres error: null value in column “id” - during
First up, you need to create a new attribute in your model (in this example we call it repeatpassword):
Next, you need to define a rule to ensure it matches your existing password attribute :
Now, when a new model is created, the model will not validate unless the password and repeatpassword attributes match. As you mentioned, this is fine for creating a new record, but you don't want to validate the matched password on the update. To create this functionality, we can use model scenarios
We simply change the repeatpassword rule as seen above to have an additional parmanter:
All that is left to do now, is when declaring your model on for the create function, use:
Instead of the normal: