Mohammad
Mohammad

Reputation: 3547

posting activeCheckBox

I want to change upload value according to the check state of the checkbox, so if it is checked the value should be 1, else, the value should be 0. here is the code in the controller:

$upload=isset($_POST['upload']);
            if($upload['value']==1){
                $model->upload=1;
                if($model->validate())
                $model->save();
            }
            else{
                $model->upload=0;
                if($model->validate())
                $model->save();
            }

and here is the code in the view:

CHtml::activeCheckBox($modelr[$j], 'upload', false, array ('value'=>1,'uncheckValue'=>0))

but in all cases the value of upload still 0 what is the problem here?

Upvotes: 0

Views: 60

Answers (1)

Sankalp Singha
Sankalp Singha

Reputation: 4546

Try changing the controller code like so :

 if(isset($_POST['Upload'])){
    $upload=$_POST['upload'];
    if($upload == 1){
        $model->upload=1;
        if($model->validate())
            $model->save();
    }
    else{
        $model->upload=0;
        if($model->validate())
            $model->save();
    }
    }

Upvotes: 1

Related Questions