class OrganizationsSearch extends Organizations
{
public $parent_short_name;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['parent_short_name'], 'string'],
// other rules
];
}
public function search($params)
{
$query = Organizations::find();
$query->alias('org');
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$query->joinWith(['parentOrganization' => function($q) {
/**
* @var ActiveQuery $q
*/
$q->alias('par_org');
}]);
$this->load($params);
$dataProvider->setSort([
'attributes' => [
'parent_short_name' => [
'asc' => ['par_org.short_name' => SORT_ASC],
'desc' => ['par_org.short_name' => SORT_DESC],
],
// other attributes
],
'defaultOrder' => [
// defaultOrders
],
]);
if (!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere(['ilike', 'org.short_name', $this->short_name]);
$query->andFilterWhere(['ilike', 'par_org.short_name', $this->parent_short_name]);
return $dataProvider;
}
}
'attribute' => 'parent_short_name',
$(document).on('beforeSubmit', '#my-form', function () {
var _this = $(this);
$.ajax({
url: _this.attr('action'),
data: _this.serialize(),
type: 'POST',
dataType: 'json',
success: function (response) {
if (response.success) {
$.pjax.reload({
container: "#my-pjax-container-id"
});
} else {
// alert
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.info(textStatus + ' ' + errorThrown);
}
});
return false;
});
public function run() {
return $this->render('callbackform', [
'model' => new Callback(),
]);
}
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<div id="callback">
<?php $form = ActiveForm::begin([
'id' => 'callback-form',
'enableAjaxValidation' => true,
'action' => Url::to(['site/callback']),
'validationUrl' => Url::to(['site/callback']),
]); ?>
<?= $form->field($model, 'name')->textInput([
'placeholder' => 'Имя',
])->label(''); ?>
<?= $form->field($model, 'phone')->textInput([
'placeholder' => 'Телефон',
])->label(''); ?>
<?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?>
<?php $form->end(); ?>
</div>