Reputation: 664
This is the structure of $this->request->data:
array(
'Capture' => array(
'items' => array (
0 => array(
'description' => '',
'amount' => ''
)
1 => array(
'description' => '',
'amount' => ''
)
)
)
)
And I have to validate this.
Upvotes: 0
Views: 780
Reputation: 1194
To validate multiple records with the same fields, you can use Model::saveAll
and pass in a parameter telling it to only validate.
Note that I don't think you can pass in your $this->request->data
(the items
level would throw it off) in the above format. It needs to either be in the format:
array(
'ModelName' => array(
'0' => array(...)
'1' => array(...)
//...
'n' => array(...)
),
)
OR:
array(
'0' => array(...)
'1' => array(...)
//...
'n' => array(...)
)
So pass it into the function in the following way:
$this->Capture->saveAll($this->request->data['Capture']['items'], array('validate' => 'only'));
Here is a similar question:
Validating multiple fields with the same name
Upvotes: 1