Skip to content

Commit

Permalink
fix save employers data (#175)
Browse files Browse the repository at this point in the history
Co-authored-by: Yurii Myronchuk <bladeroot@hiqdev.com>
  • Loading branch information
bladeroot and Yurii Myronchuk committed Nov 3, 2021
1 parent 255ca2f commit 3e966c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 5 additions & 8 deletions src/controllers/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,14 @@ public function actionUpdateEmployee($id)
}

$model = new EmployeeForm($contact, 'update');
$validationResult = $model->validate();
if (Yii::$app->request->isPost && $validationResult === true && $model->load(Yii::$app->request->post())) {
$saveResult = $model->save();
if ($saveResult === true) {
if (Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) {
Yii::$app->session->addFlash('success', Yii::t('hipanel:client', 'Employee contact was save successfully'));

return $this->redirect(['@client/view', 'id' => $model->getId()]);
}
Yii::$app->session->addFlash('error', $saveResult);
} else {
Yii::$app->session->addFlash('error', $validationResult);

$errors = $model->getFirstErrors();
Yii::$app->session->addFlash('error', implode("\n", $errors));
}

return $this->render('update-employee', [
Expand Down
8 changes: 7 additions & 1 deletion src/views/contact/_employee-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @var EmployeeForm $employeeForm
*/
use hipanel\modules\client\forms\EmployeeForm;
use borales\extensions\phoneInput\PhoneInput;
use hipanel\modules\client\models\Contact;
use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\widgets\BackButton;
Expand Down Expand Up @@ -57,7 +58,12 @@
]); ?>
<?= $form->field($model, "[$i]province"); ?>
<?= $form->field($model, "[$i]postal_code"); ?>
<?= $form->field($model, "[$i]voice_phone"); ?>
<?= $form->field($model, "[$i]voice_phone")->widget(PhoneInput::class, [
'jsOptions' => [
'preferredCountries' => array_values(array_unique(array_filter([$model->country, 'ua','us', 'gb', 'nl']))),
'initialCountry' => 'auto',
],
]) ?>
<?php Box::end() ?>

<?php Box::begin(['title' => Yii::t('hipanel:client', 'Bank details')]) ?>
Expand Down

0 comments on commit 3e966c4

Please sign in to comment.