Hello everyone,
I want to create records of three model classes with one form and prepared my form according to this tutorial in the wiki.
CActiveForm::validate supports an array of models instead of a single one. But my problem is, that if the first model fails the validation, the second and third models are not validated.
As a result in the front-end, it only says "some_field_of_the_first_model cannot be blank", although some fields of the other models are required but left blank. Not until I fill "some_field_of_the_first_model" and submit the form again, this expected error message appears.
What am I doing wrong?
PS: My create action looks like this:
public function actionCreate()
{
$item=new texItem;
$auction=new texAuction;
$sale=new texSale;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation(array($item,$auction,$sale));
if(isset($_POST['texItem'],$_POST['texAuction'],$_POST['texSale']))
{
$item->attributes=$_POST['texItem'];
$auction->attributes=$_POST['texAuction'];
$sale->attributes=$_POST['texSale'];
$transaction=$item->getDbConnection()->beginTransaction();
if($item->save() && $auction->save() && $sale->save()){
$transaction->commit();
$this->redirect(array('view','id'=>$item->id));
}else
$transaction->rollBack();
}
$this->render('create',array(
'item'=>$item,
'auction'=>$auction,
'sale'=>$sale,
));
}