Answer the question
In order to leave comments, you need to log in
Why is the model not receiving data from some fields?
There is a model, it has optional fields that are loaded by a separate view after certain actions. Validation for loaded fields works, but when submitting the form, there is no data for the loaded field in the model.
At the same time, there is no size field in attributes.
The controller itself is nothing interesting here
public function actionTest(){
$model = new PostFormTest();
$category = Category::find()->all();
$city = City::find()->all();
if($model->load(Yii::$app->request->post())){
if($model->validate()){
$this->debug($model);
}
}
return $this->render('test', compact('model', 'category', 'city'));
}
<? $form = ActiveForm::begin([
'options' => ['enctype' => 'multipart/form-data', 'id' => 'sub_category_1'],
])?>
<div class="row">
<?= $form->field($model,'size',['options' => ['class' => 'input-field col s12 m4'], 'template' =>
'{input}<label class="control-label" for="post-title">Size<span class="req"> *</span></label>{error}'])->input('number') ?>
</div>
<? $form = ActiveForm::end() ?>
Answer the question
In order to leave comments, you need to log in
There is a view in the form there is a form, there is a select in the form, when a certain option is selected, an ajax request is sent to the controller, in this controller, depending on the data received, an additional view is called in which the Size field is displayed through ActiveForm. This field is validated according to the rules described in the model, but when you click the "send" button, data comes only from the very first model, that is, data from the view that was rendered using ajax does not come.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question