Returning Data Based On Validation (Using Events?)

Hello,

I am creating a user registration system that’s a bit more complicated than your generic registration. It consists of 3 parts:

[list=1]

[*]User information (email, password, etc)

[*]API checking

[*]Using data from that API check to fetch, display, and have the user select certain values[/list]

This API check is submitted by the user via a keyID/verificationCode combo, and is checked on an external server for authenticity. The server can return an error, or it can return some values via XML sheet. If it returns the values, I would like to display those values and have the user select some (or all). After this, the form can be submitted and data stored.

I would like the registration form to show the user info inputs and keyID/vCode input, and if the keyID and vCode are authenticated, use AJAX to display the data from the server.

I’ve got half of the thing working - the user info (validation and database storage), and the API check for authenticity. However, I do not know how to use the data returned from the server to display in my registration form via AJAX

Here is the relevant code from the custom API validation check:


<?php


class apiCheck extends CValidator

{

	public $vCode;


	// if keyID already exists, do not do this


	protected function validateAttribute($object, $attribute) {

		$keyID = $object->$attribute;


		$vCodeAttr = $this->vCode === null ? $attribute.'_repeat' : $this->vCode;

		$vCode     = $object->$vCodeAttr;


		if (($this->isEmpty($keyID) || $this->isEmpty($vCode))) {

			return; }


		$api = new Pheal($keyID, $vCode); // 3rd party API access class

		try {

                        // if API is successful, gather data and do something with it

		} catch (PhealAPIException $e) {

                        // if not successful, display error

			$this->addError($object, $attribute, 'KeyID/vCode combo invalid');;

		}

	}

}




?>

and the rules array from the keys model:


array('keyID', 'ext.validators.apiCheck', 'vCode'=>'vCode', 'message' => UserModule::t("This keyID/vCode combo is invalid.")),

Now, I was thinking on possibly using Events, however I’m new to Yii and everything that I read about events just went over my head. I was thinking about raising an event in the validation code so that other code can execute, but I don’t know where to put that other code so that it will show data on the user registration form.

Also, I’m concerned that I may be looking at this wrong. In order for the validation to even start, one must submit the registration first, in which case the validation will start. Is there any way I can, via, AJAX, just submit the keyID/vCode combo, have that validated, without submitted the whole registration form until I have all needed values?

Thanks! I’ve attached the related files below.

PS: I’m using yii-user as a base to start with, but I’ve basically changed so much in it to support my registration process. I’ve also used the with related behaviors extention.