I have some fields in Model, which i want to fill in controller (not give the user to input some data..). for example: curentUserId, or current date... I found 2 solutions.
echo $this->Form->input('delivered_by', array('type' => 'hidden', 'value'=> $_SESSION['id']));
- make field hidden in view and give it a value
$_POST['data']['Sample']['delivered_by'] = 7777777;
give value in controller
if I comment in view, for example:
$this->Form->input('delivered_by');
I don't get field 'delivered_by' in data array in controller and i cant change it.
Is there any correct/wrong way? How do you others do that? Thank you, best regards,
these is how controller looks:
if ($this->request->is('post')) {
//$this->request->data['coordinate_x'] = 7777777; //=>>works with hidden field in view
$this->Sample->create();
$this->request->data['Sample']['delivered_by'] = 7;
debug($_POST);
if ($this->Sample->save($this->request->data)) {
$this->Session->setFlash(__('The sample has been saved.'));
//return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The sample could not be saved. Please, try again.'));
}
}
there is no change to 'delivered_by' variable, it stays blank;
array(
'_method' => 'POST',
'data' => array(
'Sample' => array(
'task_id' => '3',
'delivered_by' => '',
'date_of_delivery' => array(
'month' => '09',
'day' => '02',
'year' => '2014'
),
'sample_label' => '2',
'coordinate_x' => '2',
'coordinate_y' => '2',
'coordinate_z' => ''
)
)
)