Validating single form input, coming from 2 models

Hi,

Being very new to Yii I am trying to combine 2 database tables into a single form; ‘customer’ and ‘addressbook’.

I have successfully altered the generated Customer model’s actionCreate() as per this this wiki entry

and also implemented the changes described in this thread about AJAX validation.:

in $customer->actionCreate():




$this->performAjaxValidation($customer, $addressbook);



and $customer->performAjaxValidation() looks like this:




	protected function performAjaxValidation($customer, $addressbook)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='customer-form')

		{

			echo CActiveForm::validate(array($customer, $addressbook));

			Yii::app()->end();

		}

	}



The customer view _form.php has


<?php echo $form->errorSummary(array($customer, $addressbook)); ?>

Still when I load the form and submit it empty only the customer validation shows / works.

Am I missing something obvious?

Thanks!

The code you posted seems OK…

Before calling performAjaxvalidation() check that you have $_POST[‘customer’] and $_POST[‘addressbook’]…

Thanks - I found the problem with your clue; I left out the $addressbook->validate() call :rolleyes: