Yii Framework Forum: Checkboxlist In Yii Framework Multiple Check Box List With Css - Yii Framework Forum

Jump to content

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

Checkboxlist In Yii Framework Multiple Check Box List With Css Multiple check box list , get selected values and store into database Rate Topic: -----

#1 User is offline   SrikanthMaggidi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 19-May 14
  • Location:Hyderabad,India

Posted 21 May 2014 - 05:22 AM

In View::
<?php $list=CHtml::listData(Stores::model()->findAll(), 'id','store_name'); //for check box list ?>
	
	<?php echo $form->checkBoxList($model, 'event_store',$list,array(
				'separator'=>'',
				'template'=>'<div>{input}&nbsp;{label}</div>',
				'value'=>1,'uncheckValue'=>0,'checked'=>($model->event_id=='' and $model->event_id!=0 )?true:$model->event_store)); ?>


In Controller ::
<?php	
$model=new Events; 	
if(isset($_POST['Event']))
				{
					$model->attributes=$_POST['Event'];
					if($_POST['Event']['event_store']==0)
					$model->event_store=$_POST['Event']['event_store'];
					
					if($_POST['Event']['event_store']!=NULL&&$_POST['Event']['event_store']!=0)
					$model->event_store=implode(",",$_POST['Events']['event_store']);
					
					if($model->save())
					{
						$this->redirect(array('action'));		//here redirect action			
								//or
						$this->render('view');					//here render to view
					}						
				}
				
//Note:: 				
				$model->event_store=explode(',',$model->event_store); //while update the check box before render to view, need to add this line.
				
?>


Thanks
Srikanth
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