Yii Framework Forum: Checkbox in _form view file [merged duplicate post] - Yii Framework Forum

Jump to content

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

Checkbox in _form view file [merged duplicate post] Rate Topic: -----

#1 User is offline   jeewendra_kumar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 25-October 10

Posted 30 October 2010 - 02:57 PM

i need to put a checkbox in _form file of a model class.if there is a particular column in database table related to checkbox,it is appearing on the form.but i dont want to put any column for this checkbox in my database table.Also i need to put an onClick event for that checkbox.

i am using this code................

<div id="row">
<?php $form->labelEx($model,'test');
<?php $form->checkBox($model,'test');
<?php $form->error($model,'test');

this code gives an error "test" is not defined.if there is no column in database table for this checkbox

Plz help

#2 User is offline   diggy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 112
  • Joined: 18-November 09
  • Location:Ukraine, Khmelnitsky

Posted 31 October 2010 - 06:19 AM

Just alter your table like this:

ALTER table Foo add test tinyint default 0;

This will work like test is boolean value.

Then add test in your rules array in Model.

array('test', 'boolean')

Then all should work.

#3 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,557
  • Joined: 12-October 09
  • Location:Croatia

Posted 31 October 2010 - 07:02 AM

@ jeewendra_kumar

Note that you posted on wrong sub-forum "Yii-powered applications"

Moved to "General Discussion for Yii 1.1.x"
Find more about me.... btw. Do you know your WAN IP?

#4 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 31 October 2010 - 11:44 AM

Modify your model class:

class MyModel extends CActiveRecord
    public $test;

    // ...

You can also add validation rules for this new field.

#5 User is offline   ignis 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 27-April 10
  • Location:Lithuania - Vilnius

Posted 31 October 2010 - 02:29 PM

As you say, you dont need a database column, so you can use CHtml::checkBox there you can put name which you wannt it's not debend on your model becaus it is not asociated with model, if you chose CHtml::activeCheckBox then you must use your model and with simple checkBox it dont need to be used.

You can read more about this function http://www.yiiframew.../CHtml#checkBox ;)

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