multiple submit button



Am developing an application. I have three buttons in my login page.

  1. To allow user to login with username and password

  2. To render another view(manager)

  3. To render another view(inspector)

The problem is that all the three submit buttons are performing the same function of login in. why?

Please help me


CONTROL Action[/b]

public function actionLogin()





                return $this->redirect('manager');




                return $this->redirect('manager');


    if (!\Yii::$app->user->isGuest) {

        return $this->goHome();


$model = new LoginForm();

$login = new \app\models\LoginDetails();

if ($model->load(Yii::$app->request->post())) {

    $log = \app\models\User::find()->where(['user_login_id' => $_POST['LoginForm']['username'], 'is_block' => 0])->one();

    if(empty($log)) {

        \Yii::$app->session->setFlash('loginError', '<i class="fa fa-warning"></i><b> Incorrect username or password. !</b>');

            return $this->render('login', ['model' => $model]);



    $login->login_user_id = $log['user_id'];

    $loginuser = $login->login_user_id;

    $emplogin = Inspector::find()->andWhere(['contractor_user_id'=>$loginuser])->one();

    $studlogin = BuildingManager::find()->andWhere(['manager_user_id'=>$loginuser])->one();





    else if($emplogin)




    else if(!$emplogin && !$studlogin)




    else {

          \Yii::$app->session->setFlash('loginError', '<i class="fa fa-warning"></i><b> These Login credentials are Blocked/Deactive by Admin</b>');

          return $this->render('login', ['model' => $model,]);  


    $login->login_status = 1;

    $login->login_at = new \yii\db\Expression('NOW()');




    if($model->login()) {

//        if(!isset(Yii::$app->request->cookies['language'])) {

//            return $this->redirect(['language']);

 //       } else

            return $this->goBack(); 



        return $this->render('login', ['model' => $model,]);

 //   */


    else {

        return $this->render('login', [

            'model' => $model,






use yii\helpers\Html;

use yii\widgets\ActiveForm;

$this->title = Yii::t(‘app’, ‘ESS | Login’);


<div class="login-box">

  &lt;div class=&quot;login-logo&quot;&gt;


  &lt;/div&gt;&#60;&#33;-- /.login-logo --&#62;

  &lt;div class=&quot;login-box-body login-header&quot;&gt;

&lt;h1&gt;USER LOGIN&lt;/h1&gt;


  &lt;div class=&quot;login-box-body&quot;&gt;

    &lt;p class=&quot;login-box-msg&quot;&gt;&lt;?php echo Yii::t('app', 'Please fill out the following fields to login') ?&gt;&lt;/p&gt;

<?php $form = ActiveForm::begin([‘id’ => ‘login-form’,

                              'options' =&gt; ['enctype' =&gt; 'multipart/form-data'],

                              //'enableAjaxValidation' =&gt; true,


                              ]); ?&gt;

      &lt;div class=&quot;form-group has-feedback&quot;&gt;

   &lt;?= &#036;form-&gt;field(&#036;model, 'username')-&gt;textInput(['placeholder'=&gt;Yii::t('app', 'Username'), 'class'=&gt;'form-control'])-&gt;label(false) ?&gt;

        &lt;span class=&quot;glyphicon glyphicon-user form-control-feedback&quot;&gt;&lt;/span&gt;


      &lt;div class=&quot;form-group has-feedback&quot;&gt;

  &lt;?= &#036;form-&gt;field(&#036;model, 'password')-&gt;passwordInput(['class'=&gt;'form-control', 'placeholder'=&gt;Yii::t('app', 'Password')])-&gt;label(false) ?&gt;

        &lt;span class=&quot;glyphicon glyphicon-lock form-control-feedback&quot;&gt;&lt;/span&gt;


      &lt;div class=&quot;row&quot;&gt;

        &lt;div class=&quot;col-xs-7&quot;&gt;    

          &lt;div class=&quot;checkbox icheck&quot;&gt;

&lt;?= &#036;form-&gt;field(&#036;model, 'rememberMe')-&gt;checkbox() ?&gt;


        &lt;/div&gt;&#60;&#33;-- /.col --&#62;

        &lt;div class=&quot;col-xs-5&quot;&gt;

    &lt;?= Html::submitButton(Yii::t('app', 'Login'), ['class' =&gt; 'btn btn-primary btn-block btn-flat', 'id' =&gt; 'login-button', 'name' =&gt; 'login-button']) ?&gt;

        &lt;/div&gt;&#60;&#33;-- /.col --&#62;


    &#60;&#33;--a href=&quot;#&quot;&gt;I forgot my password&lt;/a--&#62;&lt;br&gt;

  &lt;/div&gt;&#60;&#33;-- /.login-box-body --&#62;

<div class="logmod__alter">

  &lt;div class=&quot;login-box-body login-manager&quot;&gt;

    &#60;&#33;--&lt;button type=&quot;button&quot; class=&quot;btn btn-block btn-primary btn-lg&quot;&gt;&lt;span&gt;New Manager? &lt;strong&gt;Create Building Manager&lt;/strong&gt;&lt;/span&gt;&lt;/button&gt;--&#62;

    &lt;?= Html::SubmitButton(Yii::t('app', '&lt;span&gt;New Manager? &lt;strong&gt;Create Building Manager&lt;/strong&gt;&lt;/span&gt;'), ['class' =&gt; 'btn btn-block btn-primary btn-lg', 'id' =&gt; 'manager-button', 'name' =&gt; 'manager-button']) ?&gt;


  &lt;div class=&quot;login-box-body login-contractor&quot;&gt;

   &#60;&#33;-- &lt;button type=&quot;button&quot; class=&quot;btn btn-block btn-success btn-lg&quot;&gt;&lt;span&gt;New Inspector? &lt;strong&gt;Create Inspector Account&lt;/strong&gt;&lt;/span&gt;&lt;/button&gt;--&#62;

   &lt;?= Html::SubmitButton(Yii::t('app', '&lt;span&gt;New Inspector? &lt;strong&gt;Create Inspector Account&lt;/strong&gt;&lt;/span&gt;'), ['class' =&gt; 'btn btn-block btn-success btn-lg', 'id' =&gt; 'inspector-button', 'name' =&gt; 'inspector-button']) ?&gt;



<?php ActiveForm::end(); ?>

  &lt;?php if(&#092;Yii::&#036;app-&gt;session-&gt;hasFlash('loginError')) : ?&gt;

  &lt;div class=&quot;alert alert-danger alert-dismissible&quot; style=&quot;margin-top: 5%;&quot;&gt;

&lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;

&lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;

&lt;?php echo &#092;Yii::&#036;app-&gt;session-&gt;getFlash('loginError'); ?&gt;


   &lt;?php endif; ?&gt;

&lt;/div&gt;&#60;&#33;-- /.login-box --&#62;

Without reading through your code in detail: Every submit button will submit the form it is in. Place buttons outside the form if you want them to do something else. Or don’t use submit buttons.

btw: Please use the "code" tags when posting code.

Please can you give me a sample of how to go about it. Am totally confused.


Maybe start with getting some basics down?


in your code you opened activeform 3 times but closed only one time. So effectively the one closed, ie the first one form is technically the only form in your webpage. all the submit buttons inside the form open tag and close tag will submit the first form.

if you close each form you can use the page as you wish.

It looks like the second and third buttons are essentially links, not form submission buttons so you can do the following:

<?= Html::a('Button Text', ['yourAction'], ['class' => 'btn btn-primary btn-block btn-flat']) ?>

And since there is really only one form you want to open and close active form once. Put the link buttons after the form close.

Thanks a lot. Your solution performs the magic.