[SOLVED] Any way to make CForm to generate checkbox with the box comes first?

Hi, while using CForm to generate forms, is there anyway to make checkboxes with the box comes first?

Eee… You mean, you want to have actual checkbox BEFORE label describing it?

Well, if yes, you have already solved this in example login page, where remember me checkbox is constructed this way. Just call $form->checkBox BEFORE $form->label:


	<div class="row rememberMe">

		<?php echo $form->checkBox($model, 'rememberMe', array('checked'=>'checked')); ?>

		<?php echo $form->label($model, 'rememberMe'); ?>

                <div class="tip"><?php echo Yii::t('forms', 'loginForm_rememberMe_add'); ?></div>

		<?php echo $form->error($model, 'rememberMe'); ?>

	</div>

Is this, what you are looking for?

@Trejder Thanks for replying! However that is not what I am looking for.

The problem I am trying to solve is, I am using form builder to generate a form. I pass in an array specifying the form definitions and it generates the html form codes for me.

The problem is, when I specify a checkbox like




...

'rememberMe'=>array(

	'type'=>'checkbox',

),

...



It gives me something like

Remember Me [x]

then if I manually overwrite it with




...

CHtml::ActiveCheckbox($this->model,'rememberMe').

CHtml::ActiveLabel($this->model, 'rememberMe'),

...



It gives me

[x] Remember Me

But the problem is it doesn’t shows validation error after validating.

Any ideas?




...

CHtml::ActiveCheckbox($this->model,'rememberMe').

CHtml::ActiveLabel($this->model, 'rememberMe'),

...



Did you put your model in your SiteController Class? couse you call $this->model , witch is incorect

when you render your action in Controller class you have to use




$this->render('view','modelName'=>$model);



then in your view you have to use




CHtml::ActiveCheckbox($modelName,'rememberMe').

CHtml::ActiveLabel($modelName, 'rememberMe'),



otherwise you have to put your model in object property in controller class and call the class metod from controller in your view

like this controler action




public function callme(){

$this->model = new Mymodel;

}



and in your view call




$this->callme();



after that you can use




CHtml::ActiveCheckbox($this->model,'rememberMe').

CHtml::ActiveLabel($this->model, 'rememberMe'),



@Igor Ivanovic, thanks for replying! I use




...

CHtml::ActiveCheckbox($this->model,'rememberMe').

CHtml::ActiveLabel($this->model, 'rememberMe'),

...



in an array that is later being pass to a CForm object, which is originally like this




return array(

  'title'=>'Login',

  'elements'=>array(

    'rememberMe'=>array(

        'type'=>'checkbox',

    ),

  ),

);



and then I tried




return array(

  'title'=>'Login',

  'elements'=>array(

     CHtml::ActiveCheckbox($this->model,'rememberMe').

     CHtml::ActiveLabel($this->model, 'rememberMe'),

  ),

);



which renders, but doesn’t validate.

Can you post the code? couse now you have to use for validation




$this->model->validate();



Found the solution using the layout property