hello eveyone, I have a form to create work schedules, I’ve created some checkboxes for each day (I’ve atached an image of the form).
this is the code from the form:
<div class="checkbox">
<?php echo $form->labelEx($model,'Dia'); ?>
<label> <?php echo $form->checkBox($model,'Dia', array('value'=>'Lunes', 'name'=>'Dia[1]'));?> Lunes</label>
<label> <?php echo $form->checkBox($model,'Dia', array('value'=>'Martes', 'name'=>'Dia[2]'));?> Martes </label>
<label> <?php echo $form->checkBox($model,'Dia', array('value'=>'Miercoles', 'name'=>'Dia[3]'));?> Miércoles </label>
<label> <?php echo $form->checkBox($model,'Dia', array('value'=>'Jueves', 'name'=>'Dia[4]'));?> Jueves </label>
<label> <?php echo $form->checkBox($model,'Dia', array('value'=>'Viernes', 'name'=>'Dia[5]'));?> Viernes </label>
<label> <?php echo $form->checkBox($model,'Dia', array('value'=>'Sábado', 'name'=>'Dia[6]'));?> Sábado </label>
<label> <?php echo $form->checkBox($model,'Dia', array('value'=>'Domingo', 'name'=>'Dia[7]'));?> Domingo </label>
<?php echo $form->error($model,'Dia'); ?>
</div>
when saving I use ‘implode’ and it saves correctly in the database.
controller:
public function actionCreate()
{
$model=new Horario;
if(isset($_POST['Horario']) and isset($_POST['Dia']))
{
$Dias =implode(", ", $_POST['Dia']);
$model->attributes=$_POST['Horario'];
$model->Dia=$Dias;
if($model->save())
$this->redirect(array('view','id'=>$model->IdHorario));
}
$this->render('create',array(
'model'=>$model,
));
}
everything works fine but when I try to update or there is an error and the form is loaded again the selected checkboxes are not checked anymore and I haven’t find a way to fix that.
thanks and sorry for my English.
gracias.