The function save only works when I remove the company_id but when I bring the company_id back the debug says "_existsIn' => 'This value does not exist'"
public function createForm(){
$user = $this->Auth->user();
$company_id = $user['company_id'];
$form_title = $_POST['form_title'];
$total_score = $_POST['total_score'];
$form = $this->FieldCoachingForms->newEntity();
if ($this->request->is('post')) {
$form->title = $form_title;
$form->deleted = 0;
$form->company_id = $company_id;
if($this->FieldCoachingForms->save($form)){
$this->Flash->success(__('Field Coaching Form has been saved!'));
}else{
$this->Flash->error(__('Something Went Wrong'));
debug($form->errors());
}
}
exit();
}
You probably have a existsIn
rule in the buildRules
of FieldCoachingModel
and a company with ID $company_id
doesn't exist.