Skip to content

Commit

Permalink
detect ajax request and render via renderAjax instead of render (#19)
Browse files Browse the repository at this point in the history
* detect ajax request and render via renderAjax instead of render

* remove else term

* add changelog entry this closes #20

* render success message via renderAjax
  • Loading branch information
martinpetrasch authored and nadar committed Oct 23, 2018
1 parent 42f7105 commit 7b71e6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file. This project make usage of the [Yii Versioning Strategy](https://github.com/yiisoft/yii2/blob/master/docs/internals/versions.md).

## 1.0.9 (23. October 2018)

+ [#19](https://github.com/luyadev/luya-module-contactform/pull/19) Use renderAjax when calling via an ajax request.

## 1.0.8.1 (4. June 2018)

+ [#17](https://github.com/luyadev/luya-module-contactform/issues/17) Fixed bug with wrong declared new line chars.
Expand Down
15 changes: 13 additions & 2 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,24 @@ public function actionIndex()
}

Yii::$app->session->setFlash('contactform_success');


if (Yii::$app->request->isAjax) {
return $this->renderAjax("index", [
"model" => $model
]);
}

return $this->refresh();
} else {
throw new InvalidConfigException('Unable to send contact email, maybe the mail component is not setup properly in your config.');
}
}


if (Yii::$app->request->isAjax) {
return $this->renderAjax('index', [
'model' => $model
]);
}
return $this->render('index', [
'model' => $model,
]);
Expand Down

0 comments on commit 7b71e6e

Please sign in to comment.