Yii 2.0如何在没有<div class =“form-group”>?</div>的情况下生成表单

时间:2014-12-22 16:44:13

标签: php yii yii2

<?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(); ?>

结果:

<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>

但我不需要包装

如何禁用此功能?

4 个答案:

答案 0 :(得分:30)

您只需使用Html::activeTextInput()

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

或更改ActiveForm::$fieldConfig配置:

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

答案 1 :(得分:9)

或者您可以这样(将div更改为span)



    $form = ActiveForm::begin([
    'id' => 'contact-form',
    'fieldConfig' => [
                        'template' => "{input}",
                        'options' => [
                            'tag'=>'span'
                        ]
    ]
    ]); 

答案 2 :(得分:6)

<?= $form->field($model, 'email', [
    'template' => '{input}', // Leave only input (remove label, error and hint)
    'options' => [
        'tag' => false, // Don't wrap with "form-group" div
    ],
]) ?>

答案 3 :(得分:3)

我已经像这样解决了....把标签作为跨度..你也可以在盒子前面加上图标。

duplicate symbol _alertController in:
/Users/.../Xcode/DerivedData/AppName-cdtbqibmmbsosrdeyqughefeazaa/Build/Intermediates/AppName.build/Debug-iphonesimulator/AppName.build/Objects-normal/x86_64/controller1.o
/Users/.../Xcode/DerivedData/AppName-cdtbqibmmbsosrdeyqughefeazaa/Build/Intermediates/AppName.build/Debug-iphonesimulator/AppName.build/Objects-normal/x86_64/controller2.o