I am trying to pass a hidden input to my controller but I get the following error:
Record not found in table “mealplans” with primary key [NULL]
When I hardcode the id in my method, like this: $id = 147; it executes the function.
In MealplansController:
public function edit($id = null)
{
//$id = 147;
$id = $this->request->getData('147');
$mealplan = $this->Mealplans->get($id, [
'contain' => [],
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$mealplan = $this->Mealplans->patchEntity($mealplan, $this->request->getData());
if ($this->Mealplans->save($mealplan)) {
$this->Flash->success(__('The mealplan has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The mealplan could not be saved. Please, try again.'));
}
$users = $this->Mealplans->Users->find('list', ['limit' => 200]);
$this->set(compact('mealplan', 'users'));
}
In my edit template:
<?php
echo $this->Form->create();
echo $this->Form->hidden('id', [
'value' => 147,
]);
echo $this->Form->button('Save Date and Event Name', ['type' => 'submit', 'class'=>'submit-btn', 'id'=>'myId', $id]);
echo $this->Form->end();
?>