Answer the question
In order to leave comments, you need to log in
Why is the form data not being validated?
There is a form
<?=$form->field($model, '_author')->label('Имя')?>
<?=$form->field($model, '_email')->label('Email')?>
<?=$form->field($model, '_comment')->label('Комментарий')->textArea(['rows' => 3])?>
<div class="form-group">
<div class="col-lg-offset-0 col-lg-1">
<?= Html::submitButton('Update', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end() ?>
public function editComment($id)
{
$comment = Comments::findOne($id);
$comment->author = $this->_author;
$comment->comment = $this->_comment;
$comment->email = $this->_email;
return $comment->save();
}
public function rules()
{
return [
[['_author', '_comment', '_email'], 'required'],
[['_author', '_comment'], 'string'],
['_email', 'email']
];
}
$model->validate()
returns false
although the data is valid. Have to use $comment->save(false)
. I can't figure out what could be the problem?
Answer the question
In order to leave comments, you need to log in
To see validation errors, it is enough to output
after $comment->save()
Why guess on coffee grounds?
Good afternoon.
Open any controller generated by crud and see how the record update is implemented there.
// тут получаете модель из метода findModel()
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
// перенаправление куда Вам надо
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question