Yii Framework Forum: Form fields rules based on user? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Form fields rules based on user? Rate Topic: -----

#1 User is offline   ZMan9854 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 23-March 10

Posted 01 May 2010 - 08:26 PM

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!
0

#2 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 01 May 2010 - 10:26 PM

View PostZMan9854, 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!



$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.
0

#3 User is offline   ZMan9854 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 23-March 10

Posted 04 May 2010 - 02:09 AM

Hah, well that should've been somewhat obvious...

Thanks!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users