gpt4 book ai didi

php - yii2 ActiveForm 字段占位符

转载 作者:可可西里 更新时间:2023-10-31 23:05:31 25 4
gpt4 key购买 nike

我想使用 yii2 ActiveForm 创建表单。这是我的代码:

<?php
$form = \yii\widgets\ActiveForm::begin([
'options' => [
'class' => 'form-inline'
]
]);
?>
<div class="form-group">
<label class="sr-only" for="example">Email</label>
<?php echo $form->field($model, 'email', [
'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
])->textInput(['placeholder' => "Enter Your Email"])->input('email')->label(false); ?>
</div>


<button type="submit" class="subscr-btn btn btn-primary btn-fill">Join</button>
<?php \yii\widgets\ActiveForm::end(); ?>

生成此 html:

<form id="w0" class="form-inline" action="/example" method="post">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail2">Email address</label>
<div class="form-group field-subscriber-email required">
<input type="email" id="subscriber-email" class="form-control transparent" name="Subscriber[email]"
autofocus="autofocus">
<div class="help-block"></div>
</div>
</div>
<button type="submit" class="subscr-btn btn btn-primary btn-fill">Join</button>

一切正常,但占位符在哪里?

最佳答案

把它放在 input() 方法中作为第二个参数 - reference

<div class="form-group">
<label class="sr-only" for="example">Email</label>
<?php echo $form->field($model, 'email', [
'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
])->textInput()->input('email', ['placeholder' => "Enter Your Email"])->label(false); ?>
</div>

关于php - yii2 ActiveForm 字段占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35245507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com