mercredi 25 juillet 2018

Registration form in modal window with Yii Framework

I'm doing a form in a modal window with Yii Framework.

I am having problems since I am using this form in a modal window and when I try to call the login I get an error saying: Undefined variable: $ modal, and the page is not even loaded.

Here I leave the modal window with the code:

<div class="modal fade in" id="abrirAcceder" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="top: 100px;">
                      <div class="modal-dialog">
                        <div class="modal-content">
                          <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><br><br>
                            <h5 class="modal-title" id="myModalLabel">
                                <i class="fa fa-user fa-lg"></i>
                                ACCEDE A TU CUENTA
                                <span class="subheader right small-link">
                                    <a href="#" data-dismiss="modal" aria-hidden="true" data-toggle="modal" data-target="#register_panel" data-reveal-id="register_panel" id="nueva-cuenta" class="radius secondary small button">CREAR NUEVA CUENTA</a>
                                </span>
                            </h5>
                          </div>
                          <div class="modal-body">
                            <div class="form">
                                <?php $form=$this->beginWidget('CActiveForm', array(
                                    'id'=>'login-form',
                                    'enableClientValidation'=>true,
                                    'clientOptions'=>array(
                                        'validateOnSubmit'=>true,
                                    ),
                                )); ?>
                                <div class="col-md-6">
                                <?php echo $form->textField($model,'username'); ?>
                                    <?php echo $form->error($model,'username'); ?>

                                </div>
                                <div class="col-md-6">
                                    <?php echo $form->passwordField($model,'password'); ?>
                                    <?php echo $form->error($model,'password'); ?>

                                </div>
                                <p class="col-md-12">
                                    <small>
                                        <i class="fa fa-lock"></i>
                                        Tu <a target="_blank" href="<?php echo Yii::app()->createUrl('/site/politica') ?>">privacidad</a>  es importante para nosotros. Nunca venderemos tu información.
                                    </small>
                                </p>
                                <div class="col-md-12">
                                    <?php echo CHtml::submitButton('Login'); ?>

                                    <a href="#" class="facebook_connect radius button facebook"><i class="fa fa-facebook-square"></i>  Haz login con facebook</a>
                                </div>
                                <?php //$this->endWidget(); ?>
                            </div><! -- div -->
                            <div class="col-md-12">
                                <hr>
                                <ul class="inline-list">
                                    <li>
                                        <small>
                                            <a href="#" data-dismiss="modal" aria-hidden="true" data-toggle="modal" data-target="#forgot_panel" data-reveal-id="forgot_panel">¿OLVIDASTE TU CONTRASEÑA?</a>
                                        </small>
                                    </li>
                                </ul>
                            </div>
                          </div> 

                        </div> 
                      </div> 
                    </div>

This modal window is in the main of the theme and inside it the different pages are loaded like the index, etc, etc.

I have been seeing that problem is fixed with ajax but I do not have much idea, if someone knows how to do it I would appreciate it.

I also leave the code of the SiteController:

public function actionLogin()
{
    $model=new LoginForm;

    // if it is ajax validation request
    if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
    {
        echo CActiveForm::validate($model);
        Yii::app()->end();
    }

    // collect user input data
    if(isset($_POST['LoginForm']))
    {
        $model->attributes=$_POST['LoginForm'];
        // validate user input and redirect to the previous page if valid
        if($model->validate() && $model->login())
            $this->redirect("index.php");
    }
    // display the login form
    $this->render('login',array('model'=>$model));
}

The LoginForm model is the basic one that Yii creates by default.

And the UserIdentity equal, I think the problem will be in those 2 pieces of code.

Thank you very much




Aucun commentaire:

Enregistrer un commentaire