My form shows the associated table array. I need the form to just show the title of the item and to input the id number in the foreign key column.
The form currently shows the array of the associated table but I can not successfully save anything. This does not require me to save anything in the associated tables.
I have an add.ctp for a BudgetExpenses Table. It has two associations. An ExpensesTitleTable and an AnnualOperatingBudgetTable. The Budget Expenses table has a annual_operating_budgets_id column and a expense_titles_id.
here is the add function in the BudgetExpensesController
public function add()
{
$budgetExpense = $this->BudgetExpenses->newEntity();
if ($this->request->is('post')) {
$budgetExpense = $this->BudgetExpenses->patchEntity($budgetExpense, $this->request->getData(), ['associated' => [ 'ExpenseTitles', 'AnnualOperatingBudgets']]);
if ($this->BudgetExpenses->save($budgetExpense)) {
$this->Flash->success(__('The budget expense has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The budget expense could not be saved. Please, try again.'));
}
$annualOperatingBudgets = $this->BudgetExpenses->AnnualOperatingBudgets->find('all');
$expenseTitles = $this->BudgetExpenses->ExpenseTitles->find('all');
$this->set(compact('budgetExpence', 'expenseTitles', 'annualOperatingBudgets'));
}
The add.ctp looks like this:
<div class="budgetExpenses form large-9 medium-8 columns content">
<?= $this->Form->create($budgetExpense) ?>
<fieldset>
<legend><?= __('Add Budget Expense') ?></legend>
<?php
echo $this->Form->control('annual_operating_budgets_id', ['label' => 'Budget Year & Institution'], ['options' => $annualOperatingBudgets ]);
echo $this->Form->control('expense');
echo $this->Form->control('expense_title_id');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
In the browser I have a drop down picker and looks like this:
The error is from the:
<?= $this->Form->create($budgetExpense) ?>