Search code examples
yii2yii2-advanced-appyii2-basic-app

Yii2: How to add textarea in yii2


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?


Solution

  • 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.