需要Yii2 HTML帮助器输入

时间:2015-11-27 15:45:04

标签: javascript yii2

我的表单是使用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库来执行此操作吗?

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

有人可能需要

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

答案 2 :(得分:1)

Red required

  

只有这段代码对我有用。分配    必需

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