title: Yii2 send id to hidden input via AJAX and reach it through POST
body: <p>I want to send the <code>data.user_id</code> to hidden input with name <code>user_id</code> and after that take it through POST in the another html::a elem. 
  My view:</p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  use yii\widgets\Pjax;
  
  /* @var $this yii\web\View */
  /* @var $searchModel app\models\PostSearch */
  /* @var $dataProvider yii\data\ActiveDataProvider */
  
  ?&gt;
  
  &lt;div class="post-index" style="position:relative;"&gt;
      &lt;div class="content"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12 search-post"&gt;
                  &lt;div class="col-md-4"&gt;
                      &lt;?= Html::a('Create Post', ['create'], ['class' =&gt; 'btn btn-primary']) ?&gt;
                      &lt;?= Html::a('Search', [''], ['class' =&gt; 'btn btn-default search-form']) ?&gt;
                      &lt;?= Html::radioList('search-type', 'search-type',
                                              ['item1' =&gt; 'by title', 'item2' =&gt; 'by tag'],
                                              [
                                                      'style' =&gt; 'display: inline-block; margin-left: 10%'
                                              ]) ?&gt;
                  &lt;/div&gt;
                  &lt;div class="col-md-8 search-input"&gt;
                      &lt;?= Html::textInput('search-info', '',['class' =&gt; 'form-control']) ?&gt;
                  &lt;/div&gt;
                  &lt;?php
                      $this-&gt;registerJs("
                          $('.search-form').on('click', function(event){
                              event.preventDefault();
                              var input = $('input[name=search-info]').val();
                              $.ajax({
                                  type : 'GET',
                                  url : '" . \yii\helpers\Url::to(['search-post']) . "?title='+input,
                                  dataType : 'json',
                                  success : function( data ){
                                      $('#posts').css('display', 'none');
                                      $('.none').fadeIn(1500);
                                      $('.title-post h3').html( data.title );
                                      $('.content-post').html( data.content );
                                      $('input[name=user_id]').val( data.user_id);
                                  }
                              });
                          });
                      ");
                  ?&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="row"&gt;
  
              &lt;div class="none" style="display: none;"&gt;
                  &lt;div class="title-post text-center"&gt;&lt;h3&gt;&lt;/h3&gt;&lt;/div&gt;
                  &lt;div class="content-post"&gt;&lt;/div&gt;
                  &lt;div class="foot-post"&gt;
  
                      &lt;form action="" method="post"&gt;
                          &lt;?= Html::hiddenInput('user_id', '') ?&gt;
                      &lt;/form&gt;
  
                      &lt;div class="text-left"&gt;
                          &lt;?= Html::a('Go To Post', ['view', 'id' =&gt; $_POST['user_id']]) ?&gt;
                      &lt;/div&gt;
  
                      &lt;div class="text-right"&gt;
                          &lt;?= Html::a('Back','index', ['class' =&gt; 'btn btn-warning']) ?&gt;
                      &lt;/div&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;?php Pjax::begin(['id' =&gt; 'posts']) ?&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;?php
  
                      foreach ($posts as $post)
                      {
                          $id = $post-&gt;user_id;
  
                          $user = $userModel::find()-&gt;where(['id' =&gt; $id])-&gt;one();
  
                          echo "&lt;div class='col-md-6 blog-post'&gt;
                                    &lt;div class='col-md-3 post-prof-img'&gt;"
                                          . Html::img('../images/' . $user-&gt;image, ['alt' =&gt; 'image', 'class' =&gt; 'tall img-circle']) .
                                    "&lt;p class='text-center title-par'&gt;&lt;strong&gt;&lt;em&gt; $user-&gt;username &lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
                                     &lt;p class='text-center'&gt; $post-&gt;date_create&lt;/p&gt;
                                    &lt;/div&gt;
                                    &lt;div class='col-md-9 post-cont'&gt;&lt;p&gt;"
                                          . Html::a('Click for more!',['view', 'id' =&gt; $post-&gt;post_id]) .
                                          "&lt;/p&gt;&lt;label class='text-center'&gt; $post-&gt;title : &lt;/label&gt;
                                          &lt;div class='fade-post'&gt;
                                              $post-&gt;content
                                          &lt;/div&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;";
                      }
                  ?&gt;
              &lt;/div&gt;
              &lt;?php Pjax::end() ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>As I can see it is not possible the way I am trying so please give some advice! Thank you in advance!</p>