December 11 2014

Yii model rules dynamic required if extension

Tagged Under :

Yii
This extension is use to validate the field is required or not required depends by another field.

For Example, now the form have 2 fields, they are Name and Email. You can set if Name was not empty then Email field will become required to force the user enter the value.

In the Model rules you just include the extension file and then set the if value for which object only.
array('email', 'ext.requiredif', 'if' => 'name')
yii rules required if

Also, you can define the values, Once the value match with the rules values define by you. Email field will become required.
array('email', 'ext.requiredif', 'if' => 'name', 'rules' => array('John', 'Jacky'))
OR
array('email', 'ext.requiredif', 'if' => 'name', 'rules' => 'John')
Now if the Name values not “John” the Email field wouldn’t be required. yii rules required if

Click here to download the extension file.

Make a Comment

You must be logged in to post a comment.