Hello,

I'm trying to use saveAll to save multiple records of a model in one
form.  Everything works fine as far as saving and validation goes
except for one little problem.  If the data entered does not validate,
the validationErrors array that is returned does not contain the
fields or the error messages for the fields that did not validate.
Here is an example setup (same as
http://teknoid.wordpress.com/2008/08/04/practical-use-of-saveall-part-2-notes-and-tips/):

view
--------------------------------------------------------------------------------------------------------
echo $form->create();

echo $form->input('0.name');
echo $form->input('0.username');
echo $form->input('0.email');
echo $form->input('0.company_id', array('type'=>'hidden',
'value'=>1));

echo $form->input('1.name');
echo $form->input('1.username');
echo $form->input('1.email');
echo $form->input('1.company_id', array('type'=>'hidden',
'value'=>1));

echo $form->end('Add');
--------------------------------------------------------------------------------------------------------


controller
--------------------------------------------------------------------------------------------------------
function add() {
   if(!empty($this->data)) {
        $this->Account->saveAll($this->data['Account'],
array('validate'=>'first'));
   }
}
--------------------------------------------------------------------------------------------------------

If I try to submit the form without entering a username for either (or
entering one that is not alphanumeric), the form does not validate,
but it does not show any errors.  When I print out $this->Account-
>validationErrors I get the following array:

Array
(
    [0] => Array
        (
        )

    [1] => Array
        (
        )

)

So it knows that entry 0 and 1 did not validate, but it doesn't return
the error messages or fields.  Has anyone encountered this problem, or
perhaps know a fix.  I created a work around for now, but it would be
nice if saveAll would display the errors.  If I do this method it
works fine:

foreach($this->data['Account'] as $k => $v)
{
        $this->Account->set($v);
        if(!$this->Account->validates())
        {
                $errors[$k] = $this->Account->validationErrors;
        }
}

if(empty($errors))
{
        // All records have validated, it is safe to save
        $this->Account->saveAll($this->data['Account']);
}
else
{
        $this->Account->validationErrors = $errors;
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to