A way to implement multiple validation?

Hi.

You know my previous topic about the two forms in one view, so here's the next problem. Until 10 minutes ago, I was calling directly ->save(), but it had the problem that if everything from form 1 is OK, it records the data and I didn't want this behavior. At least, when I was calling the ->save method to the classes $users, $usersFirms, everything was fine when it comes to errors. Both boxes appeared(I didn't find a way to join errors, so that they appear in one window only) were showing properly. However, I opened the documentation and saw the validate method. I was happy that I'd be able to validate before calling save(). However, the next problem appeared. It seems that validate stops executing the code further and gets back to the view, but thus you get the errors from the first box only. I mean, you must have filled in correctly USERNAME, PASSWORD, PASSWORD_REPEAT and EMAIL and then you will get errors for the rest fields(from the other AR model).

I opened the validate function and saw it's done this way, but in my case this is not the best implementation.

My code looks like this:



if($users->validate() && $userfirms->validate()) {


    $users->save();


    $userfirms->save();


    $this->redirect(array('show','id'=>$userfirms->USER_ID));


   }


I thought this would behave like save() and show both boxes, but it doesn't. Actually, is there a way to join the errors in the same box, when using errorSummary in view, because this would be the next problem.

Do the following:



$result1=$users->validate();


$result2=$userfirms->validate();


if($result1 && $result2)


{


}


To display errors in the same summary box, simply pass the first parameter as an array of both models. Check the API.

[/code]

Thanks again Qiang!

You may also want

$users->save(false);

to avoid performing validation twice