form design, error msg and reuse of variables flexibility

hi, i recently started using YII.

i’ve been reading and creating some sample forms based on the tutorials.

some Qs are:

1) Form flexibility: form creation is created like this=>

echo CHtml::activeTextField($model,'fullName')

. how can i change the different css for different text field. maybe for fullName textfield i want it to be bigger while other text field to be smaller. this goes for other form elements like label, etc

2) Error message: I understand error message is displayed using this=>

<?php echo CHtml::errorSummary($model); ?>

$model is an array that contains all the error msg. I understand error message can be customize in rules() function. but my Q is how can i re-position the individual error message? for instance, the error message for fullName to be displayed beside the fullName text field. Another thing is, is it possible to display the error message NOT all at once, but field by field??

Lastly for error msg, how can i use ajax validation??

3) Currently i understand that the way to create a form is to create the following:

  • Controller

  • Model

  • View

In the Model, we would most prob extend from CActiveRecord if saving into DB. and from the tutorial, we are to declare the field names (to be displayed on the form) in the class itself. so for instance a RegisterForm class would look like this:

class RegisterForm extends CActiveRecord {

	public $fullName;

	public $userName;

	public $email;

	public $passwd;

	public $passwd_repeat;

	public $gender;

	public $country;


        public function rules() {



so let say i have another class LoginForm. i would have to declare userName and passwd and do the necessary like set rules and stuff.

is there a way to put this field names into one class, and to able to reuse them for different forms. like say, a User class which contains all these fields, and when Register or Login class wants to use, it can simply take it from User class.

Looks like you don’t use Gii to generate models and controllers :) All default views can answer you questions.

Anyway read this:

and this: (3rd argument, e.g. array(‘style’=>‘border: 1px solid red;’)).

hey tks. haha well i did use the GII generator for the demos but i am trying to understand how YII works.

anws, let me try this out… tks again =)