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

rakete
  • 2,953
  • 11
  • 54
  • 108

4 Answers4

42

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,
        ],
    ],
]); 
soju
  • 25,111
  • 3
  • 68
  • 70
10

or You could something like this (change div to span)



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

10
<?= $form->field($model, 'email', [
    'template' => '{input}', // Leave only input (remove label, error and hint)
    'options' => [
        'tag' => false, // Don't wrap with "form-group" div
    ],
]) ?>
Oleg
  • 7,070
  • 4
  • 47
  • 49
  • 2
    This one is the best solution if one needs to remove wrapper only for one field. – leealex Sep 25 '17 at 09:21
  • 1
    i agree with @Oleg this is the most shortest and conventional approach , upvoting this answer – Muhammad Omer Aslam Dec 29 '17 at 16:11
  • 1
    `'tag' => null` should be `'tag' => false` per the documentation http://www.yiiframework.com/doc-2.0/yii-widgets-activefield.html#$options-detail `Setting it to false will not render a container tag.` – Craig London Feb 08 '18 at 22:12
2

I have solved it like this....put tag as span.. also you can prepend icons infront of the box.

<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(); ?>
Vikalp Veer
  • 417
  • 3
  • 7