Connor Brough
Connor Brough

Reputation: 579

Yii2 set array form field as required in model

If I have the following form field (code below) how can I set the field as required within my model so that like other fields the form cannot be submitted without it containing information.

<?= $form->field($model, 'seo[seo_title]')->textInput(['maxlength' => 60])->label('SEO Title') ?>

Upvotes: 5

Views: 3363

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133400

Add the value for te textinput in the options eg:

 <?= $form->field($model, 'seo[seo_title]')->textInput(['maxlength' => 60], 'value'=> $yourValue )->label('SEO Title') ?>

or if you only need these fields required mark required in the model

Upvotes: 1

Related Questions