How To Seperate Radiobuttons From Radiobuttonlist And Set It Default

I’m new to Yii framework. I’m using two radiobuttonlist in my advanced search form. I’m using the below lines to create radiobuttonlist.




    <div class="row">

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

                    <?php echo $form->radioButtonList($model, 'ReviewedDate', 

            array('1' => 'Reviewed', '' => 'Not Reviewed')

        ); ?>

    	</div>

    

           <div class="row"> 

    	            <?php echo $form->radioButtonList($model, 'Approved', 

            array('0' => 'Rejected', '1' => 'Approved')

        ); ?> 

    	</div> 

Now, I want to create a seperate radiobutton(4 buttons - Approved, Rejected, Reviewed, Not Reviewed) from the radiobuttonlist and Not reviewed has to be the selected by default when I go to that page.At a time only one button can be selected. How can I do this

http://www.yiiframework.com/forum/index.php/topic/23725-check-a-value-in-chtml-radio-button-list/

Hi, try this

put the code before radiobuttonlist


 <?php

                    if ($model->ReviewedDate == '') {

                        $model->ReviewedDate = 2;

                    }

?>

Rahul, I have two radiobuttonlist and I need to create 4 seperate radiobuttons. So that only one button can be selected at a time. By default Not reviewed should be checked.

Nothing changed ankit.

sorry try the code put 1




<?php

                    if ($model->ReviewedDate == '') {

                        $model->ReviewedDate = 1;

                    }

?>

can up psot the rediobuttonlist db field?

Please see the model class search function :




public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

                $criteria->with=array('apartment');

		$criteria->compare('t.Id',$this->Id);	

		$criteria->compare('Approved',$this->Approved);

		$criteria->compare('CreatedDate',$this->CreatedDate,true);

		$criteria->compare('EmailBody',$this->EmailBody,true);

		$criteria->compare('MailSubject',$this->MailSubject,true);


                $criteria->compare('MessageType',1);

		$criteria->compare('Name',$this->Name,true);


                $criteria->compare('ReviewedDate',$this->ReviewedDate);

                 

                if($this->ReviewedDate != '') 

                {

                $criteria->addCondition('ReviewedDate IS NOT NULL');

                $criteria->addCondition('updateddate > createddate');

                $criteria->compare('revieweddate','0000-00-00 00:00:00');

                }

                else 

                {

                $criteria->addCondition('updateddate = createddate');    

                $criteria->addCondition('ReviewedDate IS NULL');

                } 

		$criteria->compare('SmsText',$this->SmsText,true);

        	$criteria->compare('UpdatedDate',$this->UpdatedDate,true);

		$criteria->compare('PostedByUserFlatId',$this->PostedByUserFlatId);

		$criteria->compare('Comments',$this->Comments,true);

		$criteria->compare('ModifiedBy',$this->ModifiedBy,true);


                if (isset($this->Approved) && !empty($this->Approved)) {

                        

                        $criteria->addCondition("approved='" . $this->Approved . "'");

                        $criteria->condition = ' (updateddate > createddate) AND (revieweddate IS NOT NULL) and approved = 1 ';

                }

                else {

                        

                        $criteria->addCondition("approved='" . $this->Approved . "'");

                        $criteria->condition = ' (updateddate > createddate) AND (revieweddate IS NOT NULL) and approved = 0 ';

                }


                

		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

I tried your code. By default reviewed gets selected, but SQL query executed to fetch the rows is that of Rejected radiobutton.

Hi try this


 $criteria=new CDbCriteria;

       if($this->ReviewedDate==1){

           $criteria->condition=""     //your condition

       }else if($this->ReviewedDate==2){

           $criteria->condition="" ;      //your condition

       }