I have a form which gives the ability to add 3 records of the same
model in one go.
--------------
<?php echo $form->create('Content');?>
//First record
<?php
echo $form->input('Content.use',array('type' =>
'hidden','value'=>'yes'));
echo $form->input('Content.title',array('error' => array(
'VALID_NOT_EMPTY'=>'Title is empty' )));
echo $form->input('Content.content');
?>
//record 2
<?php
echo $form->input('Content_1.use',array('type' =>
'checkbox','value'=>'yes'));
echo $form->input('Content_1.title',array('error' => array(
'VALID_NOT_EMPTY'=>'Title is empty' )));
echo $form->input('Content_1.content');
?>
//record 3
<?php
echo $form->input('Content_2.use',array('type' =>
'checkbox','value'=>'yes'));
echo $form->input('Content_2.title',array('error' => array(
'VALID_NOT_EMPTY'=>'Title is empty' )));
echo $form->input('Content_2.content');
?>
<?php echo $form->end('Submit');?>
etc...
--------------
When available the data the folowing $this->data array is available:
------------
Array
(
[Content] => Array
(
[use] => yes
[title] => Some text
[content] => fdddf dfdf
)
[Content_1] => Array
(
[use] => yes
[title] => Some text for record 2
[content] => dsds
)
[Content_2] => Array
(
[use] => yes
[title] =>
[content] => ds
)
)
------------
In the add controller action I use the folowing code to do validation
on a record if the key 'use' is set to yes. If 'use' is not set then
no validation is required and the record will not be added to the db.
----------------
function add(){
if (!empty($this->data)) {
$this->cleanUpFields();
//check first record of model 'Content'
$this->Content->create();
$this->Content->data = $this->data;
//if record one validates then check the rest of them
if($this->Content->validates() == true){
foreach($this->data as $key => $val){
if($key != 'Content' && $val['use'] == 'yes'){
$this->Content->create();
//fed data of record 2 or 3 to the model
$this->Content->data = $val;
if($this->Content->validates() == true){
echo $key . ' is OK';
}
else{
echo $key . ' has errors';
}
}
}
echo 'OK';
//record saving code to be added...
}
else{
echo 'ERROR';
}
}
}
---------------
Validation of all records will happen. The echo statements are pure
for debugging purposes.
When validation fails on one of the records with the status 'use' =
'yes', the form will be presented again, complete with all the values
in it. Ok
My problem is; How do I get the error messages in the view for records
2 & 3??? The error messages for record 1, where fields are named after
the model, behave like expected, with error messages in place.
Thanks,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---