4

I'm using active form for the generating the form.

<?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'name') ?>
    <?= $form->field($model, 'designation') ?>
    <?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
    <?= $form->field($model, 'facbook_url')?>
    <?= $form->field($model, 'twitter_url')?>
    <?= $form->field($model, 'pinterest_url')?>

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

I want to add a custom fields in this which is not there in model.

2
  • i prefer using html helper for this task as @Vivek Doshi answer Commented Oct 20, 2016 at 6:26
  • Solution suggested by Bizley is the best way to implement custom field, which will allow you to handle validation rules also. Commented Oct 20, 2016 at 6:41

2 Answers 2

5

You can Yii HTML helper for the this.

use yii\helpers\Html;
<?= Html::textInput('first_name','',array('class'=>'form-control')) ?>

Refer the link for all the available methods for the class

http://www.yiiframework.com/doc-2.0/yii-helpers-html.html

Sign up to request clarification or add additional context in comments.

Comments

4

Just add these fields as public attributes in the class of $model and add validation rules for them.

You can find more details about this in the Guide: Creating Forms.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.