Is there a way to set form field rules for a certain users? It would be very convenient if I could do something like this:
array('status', 'safe', 'users' => '@'))
Or a variation based on the way it works for accessRules(). Possible?
I'm trying to add a couple of admin-only fields to an update form (so I don't have to make a whole extra form). I know I can set the scenario differently when it is an editor updating the form, but then the 'on' => 'update' rules do not cascade to the admin.
Also, if there could be multiple scenarios, this could allow for a workaround to this since I could just add the admin scenario.
Thanks!
Page 1 of 1
Form fields rules based on user?
#2
Posted 01 May 2010 - 10:26 PM
ZMan9854, on 01 May 2010 - 08:26 PM, said:
Is there a way to set form field rules for a certain users? It would be very convenient if I could do something like this:
array('status', 'safe', 'users' => '@'))
Or a variation based on the way it works for accessRules(). Possible?
I'm trying to add a couple of admin-only fields to an update form (so I don't have to make a whole extra form). I know I can set the scenario differently when it is an editor updating the form, but then the 'on' => 'update' rules do not cascade to the admin.
Also, if there could be multiple scenarios, this could allow for a workaround to this since I could just add the admin scenario.
Thanks!
array('status', 'safe', 'users' => '@'))
Or a variation based on the way it works for accessRules(). Possible?
I'm trying to add a couple of admin-only fields to an update form (so I don't have to make a whole extra form). I know I can set the scenario differently when it is an editor updating the form, but then the 'on' => 'update' rules do not cascade to the admin.
Also, if there could be multiple scenarios, this could allow for a workaround to this since I could just add the admin scenario.
Thanks!
$rules = array();
$rules[] = array('email','email');
if(Yii::app()->user->isAdmin)
$rules[] = array('status','required');
return $rules;
you can also use scenario for this.
array(
...
array('email', 'email'),
array('status', 'required', 'on'=>'adminCreate'),
...
);
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
Share this topic:
Page 1 of 1

Help













