我正在使用yii2进行webapp。我陷入了一个非常独特的地步需要帮助
我正在使用javascript fadeIn&淡出效果显示&隐藏表格。因此,为了实现这种效果,我必须将所有三种形式放在一个视图中。必须在按钮点击时调用相应的控制器(actionlogin,actionSignup& actionPasswordReset)。
我宣布所有三种形式的参数规则为“必要的”和“#39;用于验证,但是当我提交表单时,那个时间它没有进一步工作,因为它希望我填写其他两个表单字段以提交,因为其他两个表单也在同一视图中。
我还把我调用动画的javascript代码放在这里:
<script>
jQuery(document).ready(function() {
App.setPage("login"); //Set current page
App.init(); //Initialise plugins and elements
});
</script>
<script type="text/javascript">
function swapScreen(id) {
jQuery('.visible').removeClass('visible animated fadeInUp');
jQuery('#' + id).addClass('visible animated fadeInUp');
}
</script>
任何人都知道如何做到这一点
代码是:
<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(); ?>
我的注册页面是
<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>
&安培;我的请求重置代码是:
<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(); ?>
答案 0 :(得分:0)
Hola你可以尝试这个Make Controller actionYourview(),实例3模型并发送到视图。 示例控制器
//your login,signup and passReset model dir
use frontend\models\login;
use frontend\models\signup;
use frontend\models\passReset;
//example if the Controller is Site (defaulOne)
class SiteController extends Controller
{
//your action
public function actionYourview(){
//1 Make your 3 models for separate
$loginModel = new login();
$signupModel = new signup();
$passResetModel = new passReset();
//this will solve your problem of the three forms as 'required'
if($loginModel->load(Yii::$app->request->post()) && $loginModel){ //if Login form is summit and validate
//do your login stuff
}else if($signupModel->load(Yii::$app->request->post())){ //if $signupModel form is summit
//do your signup stuff
}else if($passResetModel->load(Yii::$app->request->post())){ //if $passreset form is summit
// do yout pass reset stuff
}else{ // and else just render and make sure that you pass your 3 models
return $this->render('Yourview',[
'loginModelToView' =>$loginModel,
'signupModelToView' =>$signupModel,
'passResetModelToView' =>$passResetModel
]);
}
}
}
并且视图只是将$ model更改为各自的模型
登录
<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(); ?>
注册
<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>
最终重置
<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(); ?>
希望这就是你的期待。祝你好运