Answer the question
In order to leave comments, you need to log in
How to change data on click on submit?
The situation is such that I need when a certain submit role clicks in the database, the value changes automatically. If an order has come to the department in more detail, it needs to be processed when the department has processed it and it is ready, when you click on the button, the status changes automatically and it is displayed in another department.
I tried doing this in the controller
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_zakaz]);
} else {
return $this->render('view', [
'model' => $this->findModel($id),
'user_name' => $user_name,
]);
}
<?php $form = ActiveForm::begin(); ?>
<?php if (Yii::$app->user->can('master')): ?>
<?= $form->field($model, 'status')->hiddenInput(['value' => '7'])->label(false) ?>
<?= Html::submitButton('Выполнено', ['class' => 'btn btn-primary']) ?>
<?php endif ?>
<?php ActiveForm::end(); ?>
Answer the question
In order to leave comments, you need to log in
1. Open the debug panel and see why, there is an answer there. We are not mediums. And you have all the answers in the debug panel at your fingertips. Maybe the request does not go there or the validation does not pass.
2. All your views can be replaced by:
<?= Html::a('Выполнить', ['check', 'id' => $model->id], [
'class' => 'btn btn-primary',
'data' => [
'confirm' => 'Вы уверены, что хотите одобрить эту ерунду?',
'method' => 'post',
],
]) ?>
public function actionCheck($id)
{
if($model = $this->findModel($id)){
$model->status = 7;
$model->save();
}
return $this->redirect(Yii::$app->request->referrer);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question