[英]Change value of attributes in a form field in Yii2
我有一個簡單的問題,那就是如何在Yii2中更改ActiveForm的aa字段的屬性值
例如:
如下代碼:
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name'); ?>
<?= $form->field($model, 'email') ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
生成此:
<input id="testform-email" class="form-control" name="TestForm[email]" aria-required="true" type="text">
我想將name和id屬性更改為自定義值。
謝謝。
您可以通過這種方式直接分配所需的屬性
<?= $form->field($model, 'name')->textInput(['id' => 'your_id', 'name' => 'your_name']); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.