简体   繁体   English

Yii2根据模型需要设置数组表单字段

[英]Yii2 set array form field as required in model

如果我有以下表单字段(下面的代码),如何在模型中按要求设置字段,以便与其他字段一样,如果表单不包含信息,则无法提交表单。

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

Add the value for te textinput in the options eg: 在选项中添加te textinput的value ,例如:

 <?= $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 或者如果您只需要这些字段,则需要在模型中标记

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM