Hi,
I'm trying to duplicate a particular entry in the form. I get all the column values by their form id, and trying to save it as a new row using saveAll. But instead of creating a new row, it is updating the existing entry.
Here is my code:
function duplicateForm($data)
{
$this->data['Form']['id']=$data['Form']['id'];
$existingForm=$this->find('all',array('conditions'=>array('Form.id'=>$this->data['Form']['id'])));
foreach($existingForm as $ex):
$this->data['Form']['name']=$ex['Form']['name']." (copy)";
$this->data['Form']['created_by']=$ex['Form']['created_by'];
$this->data['Form']['access']=$ex['Form']['access'];
$this->data['Form']['status']='Incompleted';
if($this->saveAll($this->data))
{echo "Success";}
endforeach;
}
I thought maybe since the Form name is same, it is getting updated. So I added the 'copy' string to the name of the form. Yet the old entry is only getting updated.
These are the columns of my table 'Form' and their type:
Field Type
id int(11)
name varchar(25)
created_by int(11)
access varchar(10)
created timestamp
modified timestamp
status varchar(15)
The id field is auto-increment,so I thought that If I give a save method, the id will be generated of its own.