Problem with a simple login.

Hi there,

I have been fighting all day with this login part and it just won’t work. If any kind hearted soul here could throw an eye on it, I would be grateful.

So first. What I want to achieve is a lightbox login box that accepts an email and password, and then just login the user.

I have used the Yii Foundation extension and the Modal in there to get the lightbox with a login form working.

It looks like this in the modal partial I render:


<?php $model = new LoginForm("login-form"); ?>

	<div>

		<h1>Login</h1>

		<?php 

		   $form=$this->beginWidget('foundation.widgets.FounActiveForm', array(

		    'id'=>'login-form',

		    ));

		?>

		<?php echo $form->errorSummary($model); ?>

		<?php echo $form->textFieldRow($model, "email"); ?>

		<?php echo $form->passwordFieldRow($model, "password"); ?>

		<?php echo CHtml::ajaxSubmitButton('Login',CHtml::normalizeUrl(array('site/login')), array('update'=>'#response')); ?>		

		<?php $this->endWidget(); ?>

    	<div id="response">

		</div>

	</div>

So when the user fills in the email and pass here and click on send, the post is recieved in the sitecontroller actionlogin function.

Here is my actionLogin:


public function actionLogin()

	{

		$form=new LoginForm;

		

		if(isset($_POST['LoginForm']))

		{

		

		    $form->attributes=$_POST['LoginForm'];

			if( $form->validate() )

				if( $form->login() )

					$this->redirect(Yii::app()->user->returnUrl);

		}

        }

I populate a new LoginForm with the data from the _POST, and when I tried to echo the $form->email for example the value shows up correctly. So all good so far. But it seems it never go through the validate function.

The LoginForms authenticate looks like this:


public function authenticate($attribute,$params)

	{

		if(!$this->hasErrors())

		{

			$identity=new UserIdentity($this->email,$this->password);

			$identity->authenticate();

			switch($identity->errorCode)

			{

				case UserIdentity::ERROR_NONE:

					Yii::app()->user->login($identity);

					break;

				case UserIdentity::ERROR_USERNAME_INVALID:

					$this->addError('email','Email is incorrect.');

					break;

				default: // UserIdentity::ERROR_PASSWORD_INVALID

					$this->addError('password','Password is incorrect.');

					break;

			}

		}

	}

UserIdentity looks just like in the examples out there.

But for some reason the validation doesn’t work, so when I click on the Send button nothing happens. No fields light up with error messages, and no other indications of that something goes wrong or right. Firebug says that the request went 200 OK at least.

Any ideas what I have missed?

Thanks