I'm using a form with multiplefields with the same name. After a false validation of the form i return to it with the validation messages. That all works. While the validation messages of the fields are shown correct, the entered data in the fields are gone.
Its cakephp 2.2 application without a database. (saving the data to a session for 3 pages then write it to XML)
step2.ctp:
debug($this->Form);
echo $this->Form->input('Invoice.0.InvoiceOrderNumber', array('label' => false));
echo $this->Form->input('Invoice.0.NetAmount', array('label' => false));
echo $this->Form->input('Invoice.0.CostBearer', array('label' => false));
echo $this->Form->input('Invoice.0.CostCenter', array('label' => false));
echo $this->Form->input('Invoice.0.LedgerAccount', array('label' => false));
Controller:
public function step2() {
$invoice = $this->Session->read('Invoice');
if (!isset($invoice) && is_array($invoice))
$this->redirect(array('action' => 'step1'));
else
{
$this->set('title_for_layout', 'Nieuwe interne doorbelasting');
if ($this->request->is('post')) {
debug($this->request->data);
if ($this->Invoice->validateMany($this->request->data['Invoice']))
{
if ($this->Session->write('Invoice', $this->request->data['Invoice'])) {
$this->Session->setFlash(__('The invoice has been saved'));
$this->redirect(array('action' => 'step3'));
} else {
$this->Session->setFlash(__('The invoice could not be saved. Please, try again.'));
}
}
}
}
}
debug of ($this->Form) in step2.ctp:
.....
request => object(CakeRequest) {
params => array(
'plugin' => null,
'controller' => 'invoices',
'action' => 'step2',
'named' => array(),
'pass' => array(),
'models' => array(
'Invoice' => array(
'plugin' => null,
'className' => 'Invoice'
)
)
)
data => array(
'Invoice' => array(
(int) 0 => array(
'Invoice' => array(
'InvoiceOrderNumber' => 'adfas',
'NetAmount' => '2',
'CostBearer' => '',
'CostCenter' => '',
'LedgerAccount' => ''
)
),
(int) 1 => array(
'Invoice' => array(
'InvoiceOrderNumber' => 'adaaaaaaaaa',
'NetAmount' => 'bbbbbbbbb',
'CostBearer' => '',
'CostCenter' => '',
'LedgerAccount' => ''
)
)
)
)
....
So the data is there, but cake doesn't put it in the fields. But i can't figger out why...
['Invoice'][0]['Invoice']['NetAmount]. How are you generating that array?