繁体   English   中英

Yii2 HTML助手输入要求

[英]Yii2 HTML helper input make required

有用HTML helper生成的表单:

<div class="row">
  <div class='form-group col-lg-6 col-sm-6'>
    <?= HTML::label('Name:','PropertyContactsNew',['class' => 'control-label']); ?>
    <?= HTML::textInput("PropertyContactsNew[{$slug_other_contacts}][name][]", '', ['maxlength' => 50, 'class'=>'form-control']) ?>
  </div>
  <div class='form-group col-lg-6 col-sm-6'>
    <?= HTML::label('Company:','PropertyContactsNew',['class' => 'control-label']); ?>
    <?= HTML::textInput("PropertyContactsNew[{$slug_other_contacts}][company][]", '', ['maxlength' => 100, 'class'=>'form-control']) ?>
  </div>
</div>

有没有一种方法可以标记表单字段,并防止表单为空,就像ActiveForm一样(由于某些原因,我不能使用ActiveForm),还是应该使用js库来执行此操作?

我认为您可以创建一个扩展Model类的FormModel,以便您可以处理所需的每个验证。

可能有人需要

<?= HTML::label('Name:','PropertyContactsNew',['class' => 'control-label','required'=>true]); ?>

红色必填

仅此代码对我有用。 需要的DIV

<div class="form-group required">
     <?= Html::label('Pressed digit', 'pressed_digit', ['class' => 'control-label']) ?>
</div>

暂无
暂无

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

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