Example #1
0
<?php

use roman444uk\yii\widgets\ActiveForm;
use yii\helpers\Html;
$searchModel = $this->params['searchModel'];
?>

<div id="search-container">
    <?php 
$form = ActiveForm::begin(['id' => 'search-form', 'method' => 'get', 'action' => '/']);
echo $form->field($this->params['searchModel'], 'content', ['template' => '{input}', 'options' => ['tag' => false]])->textInput(['name' => !$this->params['directPopulating'] ? 'content' : null]);
echo Html::submitInput('', ['class' => 'icon sm zoom']);
ActiveForm::end();
?>
</div>

<?php 
$js = <<<JS
jQuery('#search-form').on('submit.yiiActiveForm', function(event) {
    \$.pjax.submit(event, '#advert-list-pjax');
});
JS;
$this->registerJs($js);
 /**
  * 
  * @param type $id
  * 
  * @return type
  */
 public function actionValidate($id = null)
 {
     $request = Yii::$app->getRequest();
     if (!$request->isAjax) {
         throw new NotFoundHttpException();
     }
     if ($id) {
         $model = $this->findModel($id);
     } else {
         $model = new $this->modelClass();
     }
     $model->load($request->post());
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ActiveForm::validate($model);
 }