Reputation: 1160
I have an active form model which has fields I do not wish to set any validation rules for. The problem is that Yii does not set these fields when I submit the form unless I assign some validation rule to them.
The fields are optional and free-form, so I don't want to assign a validation rule. Any suggestions?
Upvotes: 0
Views: 475
Reputation: 437494
Use the special "safe" rule:
Sometimes, we want to declare an attribute to be safe, even though we do not really have any specific rule for it. An example is an article's content attribute which can take any user input. We can use the special
safe
rule to achieve this goal.
$rules = array(
'myfield' => 'safe',
);
This rule does not place any restrictions on the field (so you are free to leave it empty); it just tells Yii that you want the field to be set on the model whenever the model is populated from an external source.
Upvotes: 2