I have a simple problem that I can’t seem to solve. I’m using pjax to create a form and update a field. It’s fairly simple. However, I’d like to submit the form via pjax and simply update the page without the url changing. The only way I am able to do this is by using a redirect. This is fine, but I’d like to know how to achieve this without a redirect.
Here’s the code.
Controller action
public function actionEditProfile()
{
$pro = Profile::findOne(Yii::$app->user->identity->id);
if ($pro->load(Yii::$app->request->post())) {
if ($pro->save()) {
// return $this->redirect('my-profile');
return $this->render('myProfile', ['prof' => $pro]);
}
}
return $this->renderAjax('_editProf', ['prof' => $pro]);
}
View (myProfile)
$this->title = Yii::$app->user->identity->username;
$this->params['breadcrumbs'][] = $this->title;
?>
<div id="profile">
<h1><?= Html::encode($this->title) ?></h1>
<p><b>About Me</b><br>
<?= Html::encode($prof->description)?></p>
<br>
<br>
<?= Html::a("Edit Profile",['edit-profile'], ['id' => 'editProfile', 'class' => 'btn btn-primary', 'data-pjax'=>'profile']);?>
</div>
<?php Pjax::begin(['id'=>'profile', 'linkSelector'=>'#editProfile', 'enablePushState'=>false, 'timeout'=>10000]); ?>
<?php Pjax::end(); ?>
and the partial view for pjax (_editProfile)
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']],['id' => 'editpro']); ?>
<?= $form->field($prof, 'description')->textarea() ?>
<br>
<br>
<?= Html::submitButton('Save', ['class' => 'btn btn-primary', 'name' => 'save-profile']) ?>
<?php ActiveForm::end(); ?>
</div>
As you can see, I tried using render, but that yields the following in the URL.
edit-profile?_pjax=%23profile
And I’d like for it to remain “my-profile” without reloading the entire page.
Some help would be appreciated.
Thank you