Using Jquery To Load Page Section From Controller

I have a Login form and registration form on the same page. They are in separate <div> tags, that appear and hide using jquery:




jQuery('#register-btn').click(function () {

            jQuery('.login-form').hide();

            jQuery('.register-form').show();

        });



I have a controller action that reads the POST request sent by the registration form. I want the controller to send the user back to the registration form if there are errors in the inputs. Here is the snippet from my controller:




public function actionLogin()

	{

...


$accessRequest = new AccessRequest();

            

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

            {

                $accessRequest->attributes = $_POST['AccessRequest'];

                //validate user input and save access request

                if ($accessRequest->save())

                {

                    Yii::app()->user->setFlash('success', '<strong>Done!</strong> A Request has been submitted. Someone will be in touch with you shortly');                    

                    $accessRequest->unsetAttributes();

                }

                else

                {

                    if ($accessRequest->hasErrors())

                    {

                        Yii::app()->user->setFlash('errorReg', CHtml::errorSummary($accessRequest));

                        

                    }                        

                }

            }

...

$this->render('login', array('loginModel' => $loginModel, 'accessRequest' => $accessRequest));



How can I send the user back to the registration section of the Login page from the controller?

Any help would be great.

Thanks.

–Bhavik

I’ve solved the Issue.

Instead of using the controller to pass the jQuery to the page, I’ve used the


Yii::app()->user->hasFlash()

function to determine whether or not to show the register form.




<?php 

    		if (Yii::app()->user->hasFlash('errorReg')){

    	?>

                <script>

                    jQuery('.login-form').hide();

                    jQuery('.register-form').show();

                </script>

                

    		<div class="alert in alert-block fade alert-error">

    		<?php echo Yii::app()->user->getFlash('errorReg');?>		

    			

    		</div>

    	<?php 	

    		}

    		$cs = Yii::app()->getClientScript();

    		$selector = "#yw0 .alert";

			$cs->registerScript(__CLASS__.'#yw0', "jQuery('{$selector}').alert();");    		

    	?>



This works for now, but I am open to hear if there are any other better solutions.