簡體   English   中英

在Yii2的表單字段中更改屬性的值

[英]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">

我想將nameid屬性更改為自定義值。

謝謝。

您可以通過這種方式直接分配所需的屬性

<?= $form->field($model, 'name')->textInput(['id' => 'your_id', 'name' => 'your_name']); ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM