Yii2:Does login,signup & password reset forms work together in single view -
i using yii2 webapp. got stuck @ unique point & need help
i using javascript fadein & fadeout effect show & hide form. enable effect have put 3 forms in single view & have call respective controllers(actionlogin, actionsignup & actionpasswordreset) on button click.
i declared rules parameters of 3 forms 'required' validation when submit form, time not working further wants me fill other 2 form fields submit other 2 forms in same view.
i put javascript code call animation here:
<script> jquery(document).ready(function() { app.setpage("login"); //set current page app.init(); //initialise plugins , elements }); </script> <script type="text/javascript"> function swapscreen(id) { jquery('.visible').removeclass('visible animated fadeinup'); jquery('#' + id).addclass('visible animated fadeinup'); } </script>
anyone knows how this
code is:
<section id="login" class="visible"> <?php $form = activeform::begin(['id' => 'login-form', 'options' => array('role' => 'form')]); ?> <div class="form-group"> <?= $form->field($model, 'email_address',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?> </div> <div class="form-group"> <?= $form->field($model, 'password', ['template' => "{label}\n<i class='fa fa-lock'></i>\n{input}\n{hint}\n{error}"])->passwordinput(); ?> </div> <div class="form-actions"> <?= $form->field($model, 'rememberme',['template' => "{input} {label}"])->checkbox(); ?> <?= html::submitbutton('submit', ['class' => 'btn btn-danger', 'name' => 'login-button']) ?> </div> <?php $form = activeform::end(); ?>
my signup page
<section id="register" class="visible"> <?php $form = activeform::begin(['id' => 'signup-form', 'options' => array('role' => 'form')]); ?> <div class="form-group"> <?= $form->field($model, 'full_name',['template' => "{label}\n<i class='fa fa-font'></i>\n{input}\n{hint}\n{error}"]); ?> </div> <div class="form-group"> <?= $form->field($model, 'email',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?> </div> <div class="form-group"> <?= $form->field($model, 'input_password',['template' => "{label}\n<i class='fa fa-lock'></i>\n{input}\n{hint}\n{error}"])->passwordinput() ?> </div> <div class="form-group"> <?= $form->field($model, 'input_confirm_password',['template' => "{label}\n<i class='fa fa-check-square-o'></i>\n{input}\n{hint}\n{error}"])->passwordinput() ?> </div> <div class="form-actions"> <?= $form->field($model, 'agreetc',['template' => "{input}"])->checkbox(['class' => 'uniform']); ?> <?= html::submitbutton('signup', ['class' => 'btn btn-success', 'name' => 'signup-button']) ?> </div>
& request reset code is:
<section id="forgot" class="visible"> <?php $form = activeform::begin(['id' => 'request-password-reset-form']); ?> <div class="form-group"> <?= $form->field($model, 'reset_email',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?> </div> <div class="form-actions"> <?= html::submitbutton('send me reset instructions', ['class' => 'btn btn-info', 'name' => 'reset-button']) ?> </div> <?php $form = activeform::end(); ?>
hola try make controller actionyourview() , instance 3 models , send view. example controller
//your login,signup , passreset model dir use frontend\models\login; use frontend\models\signup; use frontend\models\passreset; //example if controller site (defaulone) class sitecontroller extends controller { //your action public function actionyourview(){ //1 make 3 models separate $loginmodel = new login(); $signupmodel = new signup(); $passresetmodel = new passreset(); //this solve problem of 3 forms 'required' if($loginmodel->load(yii::$app->request->post()) && $loginmodel){ //if login form summit , validate //do login stuff }else if($signupmodel->load(yii::$app->request->post())){ //if $signupmodel form summit //do signup stuff }else if($passresetmodel->load(yii::$app->request->post())){ //if $passreset form summit // yout pass reset stuff }else{ // , else render , make sure pass 3 models return $this->render('yourview',[ 'loginmodeltoview' =>$loginmodel, 'signupmodeltoview' =>$signupmodel, 'passresetmodeltoview' =>$passresetmodel ]); } } }
and view change $model respective model
login
<section id="login" class="visible"> <?php $form = activeform::begin(['id' => 'login-form', 'options' => array('role' => 'form')]); ?> <div class="form-group"> <?= $form->field($loginmodeltoview, 'email_address',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?> </div> <div class="form-group"> <?= $form->field($loginmodeltoview, 'password', ['template' => "{label}\n<i class='fa fa-lock'></i>\n{input}\n{hint}\n{error}"])->passwordinput(); ?> </div> <div class="form-actions"> <?= $form->field($loginmodeltoview, 'rememberme',['template' => "{input} {label}"])->checkbox(); ?> <?= html::submitbutton('submit', ['class' => 'btn btn-danger', 'name' => 'login-button']) ?> </div> <?php $form = activeform::end(); ?>
signup
<section id="register" class="visible"> <?php $form = activeform::begin(['id' => 'signup-form', 'options' => array('role' => 'form')]); ?> <div class="form-group"> <?= $form->field($signupmodeltoview, 'full_name',['template' => "{label}\n<i class='fa fa-font'></i>\n{input}\n{hint}\n{error}"]); ?> </div> <div class="form-group"> <?= $form->field($signupmodeltoview, 'email',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?> </div> <div class="form-group"> <?= $form->field($signupmodeltoview, 'input_password',['template' => "{label}\n<i class='fa fa-lock'></i>\n{input}\n{hint}\n{error}"])->passwordinput() ?> </div> <div class="form-group"> <?= $form->field($signupmodeltoview, 'input_confirm_password',['template' => "{label}\n<i class='fa fa-check-square-o'></i>\n{input}\n{hint}\n{error}"])->passwordinput() ?> </div> <div class="form-actions"> <?= $form->field($signupmodeltoview, 'agreetc',['template' => "{input}"])->checkbox(['class' => 'uniform']); ?> <?= html::submitbutton('signup', ['class' => 'btn btn-success', 'name' => 'signup-button']) ?> </div>
finaly reset
<section id="forgot" class="visible"> <?php $form = activeform::begin(['id' => 'request-password-reset-form']); ?> <div class="form-group"> <?= $form->field($passresetmodeltoview, 'reset_email',['template' => "{label}\n<i class='fa fa-envelope'></i>\n{input}\n{hint}\n{error}"]); ?> </div> <div class="form-actions"> <?= html::submitbutton('send me reset instructions', ['class' => 'btn btn-info', 'name' => 'reset-button']) ?> </div> <?php $form = activeform::end(); ?>
hope looking. luck
Comments
Post a Comment