Answer the question
In order to leave comments, you need to log in
Why is the controller not seeing form data in yii2?
The logic is this application: you need to make a confirmation by entering a certain number in the form field that comes already with the data. There is a controller
public function actionCreate()
{
$model = new Transactions();
if ($model->load(Yii::$app->request->post()) && $this->applyOperation($model)) {
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
private function applyOperation($model) {
$code = $model->code;
$password = 123;
if($password == $code ){
return $this->redirect(['trans']);
}
<?php $form = ActiveForm::begin(); ?>
<?= Html::activeTextInput($model, 'account', [ 'value' => "$acc",'readonly' => 'readonly']) ?>
<?= Html::activeTextInput($model, 'sum', [ 'value' => "$su",'readonly' => 'readonly']) ?>
<?= Html::activeTextInput($model, 'description', [ 'value' => "$desc",'readonly' => 'readonly']) ?>
<?= Html::activeTextInput($model, 'sender', [ 'value' => "$se",'readonly' => 'readonly']) ?>
<?= $form->field($model, 'code')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('frontend', 'Fill up balance') : Yii::t('frontend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
Answer the question
In order to leave comments, you need to log in
Try like this:
public function actionCreate()
{
$model = new Transactions();
if ($model->load(Yii::$app->request->post()) {
$this->applyOperation($model);
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
private function applyOperation($model) {
$code = $model->code;
$password = 123;
if($password == $code ){
return $this->redirect(['trans']);
}else{
return true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question