I have a checkbox named required,where if the checkbox is clicked its value is 1,otherwise its 0. The value is correctly passed form the view file to the controller. The model file gets the value from the controller, but the value is not being saved.
I echoed the required value in the model,to check if the value is received. The value is echoed as 1. But in the database,it is not updated.
This is my code:
function updateFieldEntries($data)
{
$this->data['Attribute']['id']=$this->Attribute->find('all', array(
'fields' => array('Attribute.id'),
'order' => 'Attribute.id DESC' ));
$this->data['Attribute']['id']=$this->data['Attribute']['id'][0]['Attribute']['id'];
$this->data['Attribute']['form_id'] = $this->find('all', array(
'fields' => array('Form.id'),
'order' => 'Form.id DESC'));
$this->data['Attribute']['form_id']=$this->data['Attribute']['form_id'][0]['Form']['id'];
$this->data['Attribute']['instructions']=$data['Attribute']['instructions'];
$this->data['Attribute']['required']=$data['Attribute']['required'];
echo " required model ".$this->data['Attribute']['required'];
$this->data['Attribute']['sequence_no'] =$this->Attribute->find('all', array(
'conditions' => array('Attribute.form_id' =>$this->data['Attribute']['form_id']),
'fields' => array('Attribute.sequence_no'),
'order' => 'Attribute.sequence_no DESC'));
$this->data['Attribute']['sequence_no']=$this->data['Attribute']['sequence_no'][0]['Attribute']['sequence_no'];
if($data['Attribute']['name']== ''){
$this->data['Attribute']['label']=$this->Attribute->find('all', array(
'conditions' => array('Attribute.id' =>$this->data['Attribute']['id']),
'fields' => array('Attribute.label') ));
$this->data['Attribute']['label']=$this->data['Attribute']['label'][0]['Attribute']['label'];
}
else{
$this->data['Attribute']['label']= $data['Attribute']['name'];
}
if($data['Attribute']['size']== ''){
$this->data['Attribute']['size']=$this->Attribute->find('all', array(
'conditions' => array('Attribute.id' =>$this->data['Attribute']['id']),
'fields' => array('Attribute.size') ));
$this->data['Attribute']['size']=$this->data['Attribute']['size'][0]['Attribute']['size'];
}
else{
$this->data['Attribute']['size']= $data['Attribute']['size'];
}
if($data['Attribute']['instructions']== ''){
$this->data['Attribute']['instructions']=$this->Attribute->find('all', array(
'conditions' => array('Attribute.id' =>$this->data['Attribute']['id']),
'fields' => array('Attribute.instructions') ));
$this->data['Attribute']['instructions']=$this->data['Attribute']['instructions'][0]['Attribute']['instructions'];
}
$this->Attribute->save($this->data);
}
EDIT
I also checked if the required value alone is being saved using saveField option.
$this->Attribute->saveField('required',$this->data['Attribute']['required']);
The value 1 got stored in a separate row in the table for that particular attribute. So what is the problem, why is it not getting saved along with the other values.
EDIT
If I save an integer value directly,like
$this->data['Attribute']['required']='7';
it gets stored in the database. How?? What is the problem then??