Yii 2.0 如何在没有<div class="form-group">的情况下生成表单? [英] Yii 2.0 How to generate form without <div class="form-group">?

查看:26
本文介绍了Yii 2.0 如何在没有<div class="form-group">的情况下生成表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 'contact-form']);?><?= $form->field($model, 'email', ['输入选项' =>[ '占位符' =>'Ihre E-Mail Adresse', 'class' =>'时事通讯-cta-mail']])->标签(假)->文本输入();?><?= Html::submitButton('20€ Gutschein sichern', ['class' => 'green newsletter-cta-button', 'name' => 'contact-button', 'value' =>;'你好']) ?><?php ActiveForm::end();?>

结果为:

<input type="hidden" name="_csrf" value="WFlFWnIwU1Y3HnQKSn06GG46PXcjQRUzNCA9KhRiYCxvFXQ9RHIiPA=="><div class="form-group field-newsletterform-email required has-error"><input type="text" id="newsletterform-email" class="newsletter-cta-mail" name="NewsletterForm[email]" placeholder="Ihre E-Mail Adresse"><p class="help-block help-block-error">验证码不能为空.</p>

<button type="submit" class="green newsletter-cta-button" name="contact-button" value="hallo">20€ Gutschein sichern</button></form>

但我不需要包装

如何禁用此功能?

解决方案

你可以简单地使用 Html::activeTextInput() :

 'Ihre E-Mail Adresse', 'class' => 'newsletter-cta-mail']);?>

或者更改ActiveForm::$fieldConfig 配置:

ActiveForm::begin(['id' =>'联系表','fieldConfig' =>['选项' =>['标签' =>错误的,],],]);

<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
        <?= $form->field($model, 'email',  [
                'inputOptions' => [ 'placeholder' => 'Ihre E-Mail Adresse', 'class' => 'newsletter-cta-mail' ]
        ])->label(false)->textInput(); ?>
        <?= Html::submitButton('20€ Gutschein sichern', ['class' => 'green newsletter-cta-button', 'name' => 'contact-button', 'value' => 'hallo']) ?>
<?php ActiveForm::end(); ?>

results into:

<form id="contact-form" action="/" method="post" role="form">
<input type="hidden" name="_csrf" value="WFlFWnIwU1Y3HnQKSn06GG46PXcjQRUzNCA9KhRiYCxvFXQ9RHIiPA==">     <div class="form-group field-newsletterform-email required has-error">

<input type="text" id="newsletterform-email" class="newsletter-cta-mail" name="NewsletterForm[email]" placeholder="Ihre E-Mail Adresse">

<p class="help-block help-block-error">Verification Code cannot be blank.</p>
</div>  <button type="submit" class="green newsletter-cta-button" name="contact-button" value="hallo">20€ Gutschein sichern</button></form>

But I dont need the wrapping

How to disable this?

解决方案

You could simply use Html::activeTextInput() :

<?= Html::activeTextInput($model, 'email', ['placeholder' => 'Ihre E-Mail Adresse', 'class' => 'newsletter-cta-mail']); ?>

Or change ActiveForm::$fieldConfig configuration :

ActiveForm::begin([
    'id' => 'contact-form',
    'fieldConfig' => [
        'options' => [
            'tag' => false,
        ],
    ],
]); 

这篇关于Yii 2.0 如何在没有&lt;div class="form-group"&gt;的情况下生成表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆