Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii 2.0 How to generate form without <div class="form-group">?

Tags:

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

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?

like image 514
rakete Avatar asked Dec 22 '14 16:12

rakete


People also ask

What is active form yii2?

ActiveForm is a widget that builds an interactive HTML form for one or multiple data models. For more details and usage information on ActiveForm, see the guide article on forms.


1 Answers

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,         ],     ], ]);  
like image 187
soju Avatar answered Sep 17 '22 21:09

soju