title: Yii2 Form in Modal Window
body: <p>I would like to understand the basics of how to work with form from Modal window in Yii2? This is my current understanding and I will be grateful if someone can explain me what I missed.
  So, I have a ListView with records. Each record contains a button. The button opens a Modal with a Form inside:</p>
  
  <pre><code>echo Html::a('&lt;span class="glyphicon glyphicon-bell" aria-hidden="true"&gt;&lt;/span&gt;', ['#'],[
                           'id' =&gt; $model-&gt;id,
                           'class' =&gt; 'linkbutton',
                           'data-toggle'=&gt;'modal',
                           'data-tooltip'=&gt;'true',
                           'data-target'=&gt;'#submit_vote'.$model-&gt;id,
                           'title'=&gt; 'Assign'
                       ]);
  
                  Modal::begin([
                      'size' =&gt; 'modal-lg',
                      'options' =&gt; [
                          'id' =&gt; 'submit_vote'.$model-&gt;id,
                      ],
                      'header' =&gt; '&lt;h2&gt;Create Vote&lt;/h2&gt;',
                      'footer' =&gt; 'Footer'
                  ]);
  
                  ActiveForm::begin([
                      'action' =&gt; 'vote/vote',
                      'method' =&gt; 'post',
                      'id' =&gt; 'form'.$model-&gt;id
                  ]);
  
                  echo Html::input(
                          'type: text',
                          'search',
                          '',
                          [
                              'placeholder' =&gt; 'Search...',
                              'class' =&gt; 'form-control'
                          ]
                  );
  
                  echo Html::submitButton(
                          '&lt;span class="glyphicon glyphicon-search"&gt;&lt;/span&gt;',
                          [
                              'class' =&gt; 'btn btn-success',
                          ]
                  );
                  ActiveForm::End();
                  Modal::end();
  </code></pre>
  
  <p>In Form 'action' I wrote vote/vote and method post. So I expect post data inside actionVote function of my VoteController.</p>
  
  <pre><code>public function actionVote()
      {
          if (Yii::$app-&gt;request-&gt;post()) {
          $id = Yii::$app-&gt;request-&gt;post('search');
          Yii::$app-&gt;session-&gt;setFlash('error', $id);
          return true; 
          }
      }
  </code></pre>
  
  <p>For submitting I use an ajax:</p>
  
  <pre><code>$('form').on('submit', function () {
      alert($(this).attr('id')+$(this).attr('action')+$(this).serialize());  //just to see what data is coming to js
      if($(this).attr('id') !== 'searchForm') {  //some check
              $.ajax({
              url: $(this).attr('action'),
              type: 'post',
              data: $(this).serialize(),
              success: function(){
                  $("#submit_vote15").modal('hide'); //hide popup  
              },
          });  
          return false;
      }
  </code></pre>
  
  <p>But after click on Submit form I see two alerts. Modal also not hidden. Flash message also is not showed.
  What I am doing wrong? Can anyone clearly explain a step by step procedure of data flow? For now my understanding is:</p>
  
  <ol>
  <li>Open Modal;</li>
  <li>Click Form Submit inside Modal;</li>
  <li>Load data via ajax to controller action;</li>
  <li>catch data from post and execute controller action code;
  What I missed?</li>
  </ol>