Подтвердить что ты не робот

Yii 2.0 Как сгенерировать форму без <div class= "form-group" >?

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

Но мне не нужна упаковка

Как отключить это?

4b9b3361

Ответ 1

Вы можете просто использовать 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,
        ],
    ],
]); 

Ответ 2

Или вы можете что-то вроде этого (измените div на span)



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

Ответ 3

Я решил это, как это.... put tag as span.. Также вы можете добавлять значки в рамку окна.

<div id="login-box-inner">
    <?php $form = ActiveForm::begin([
        'id' => 'login-form',
        'options' => ['role'=>'form'],

        'fieldConfig' => [
            'options' => [
                'tag' => 'span',
            ],

        ],
    ]); ?>

    <?= $form->field($model, 'username',[
        'template' => '
            <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-user emerald"></i></span>
                {input}
            </div>
            {error}',
        'inputOptions' => [
            'placeholder' => 'Username ...',
            'class'=>'form-control',
        ]])
    ?>


    <?= $form->field($model, 'password', [
            'template' => '
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-key emerald"></i></span>
                    {input}
                </div>
                {error}',
            'inputOptions' => [
                'placeholder' => 'Password ...',
                'class'=>'form-control',
            ]])->input('password')
    ?>

    <?php ActiveForm::end(); ?>

Ответ 4

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