Yii2: How to add textarea in yii2

user4428957 picture user4428957 · Jan 14, 2015 · Viewed 55.4k times · Source

What is the mapping of textarea in yii2 ? How to write this in yii2 format?

<textarea  name="downloadSourceCode" id="downloadSourceCode"></textarea>

What is an alternative or way to define textarea in yii2?

Answer

Qurashi picture Qurashi · Jan 14, 2015

You can use Active Forms to create fields like textarea for example

<?php $form = ActiveForm::begin(['id' => 'downloadSourceCode']); ?>
<?= $form->field($model, 'description')->textarea(['rows' => '6']) ?>
<?= Html::submitButton('Submit') ?>
<?php ActiveForm::end(); ?>

In the previouse example you are creating a form with a textarea inside, you can give it a name and pass the model from the controller to show the existing content of the model if you are editing it, if you are creating a new model, you will need to create a new object and then pass it to the view.