Is that any way to show the Html::textArea without encode the content?

I try to use the default


<?= $form->field($model, 'attribute_name')->textarea() ?>

But it always “encode” the value which I don’t want it happen.

I would like to decode the value I have in the database.

I want to show it like this:


<textarea><?= Html::decode($model->attribute_name); ?></textarea>

Is that anyway that Yii 2 have build in decode


<textarea>

function?

I want this answer too

I have bumped into this a few times before but have not found a solutions yet.

When I look into the core code. I think Yii 2 did not offer a decode function for the textarea.

Here is my solution for this decode the textarea.




<?php

// You need to include HTML at the beginning.

use yii\helpers\Html;

use yii\bootstrap\ActiveForm;

?>


<!-- Temp Demo Website: http://www.onbook.ca/slicer/web/index.php/config/printer-setting?tab=custom_gcode -->


<?php 

$form = ActiveForm::begin([

    'id' => 'slic3r-config-form-custom-gcode',

    'options' => ['class' => 'form-horizontal'],

	'fieldConfig' => [

            'template' => "<div class=\"col-lg-12 col-md-12 col-sm-12 \">{input}</div>\n<div class=\"col-lg-12 col-md-12 col-sm-12\">{error}</div>",

            'labelOptions' => ['class' => 'col-lg-3 col-md-3 col-sm-4 control-label'],

     ],

		

]) ?>




<!-- Note: My $model = $Slic3rConfig; $attribute = 'start_gcode'; you need to change to yours if you want o use my code. -->


<fieldset>

<legend><?= Yii::t('app', 'Start Edit') ?></legend>

<div class="form-group  <?php echo 'field-'.Html::getInputId($Slic3rConfig, 'start_gcode') ?>">

<div class="col-lg-12 col-md-12 col-sm-12 ">

<textarea rows="6" id="<?php echo Html::getInputId($Slic3rConfig, 'start_gcode') ?>" name="<?php echo Html::getInputName($Slic3rConfig, 'start_gcode'); ?>" class="form-control"><?= Html::decode(Html::getAttributeValue($Slic3rConfig, 'start_gcode')); ?></textarea>

</div>

<div class="col-lg-12 col-md-12 col-sm-12"><p class="help-block help-block-error"></p></div>

</div>


<!-- IMPORTANT NOTE 1: YOU NEED TO INCLUDE THE ORIGINAL TEXTAREA FIELD! THIS WILL HELP YOU TO TRIGGER ALL THE VALIDATION JAVASCRIPT FUNCTIONS-->

<div style="display:none;">   <?= $form->field($Slic3rConfig, 'start_gcode')->textarea(['name'=>'hidden-start_gcode']) ?></div>

<!-- IMPORTANT NOTE 2: YOU NEED TO SET THE ORIGINAL TEXTAREA NAME TO SOMETHING ELSE IN ORDER TO MAKE IT WORK! WITH TWO SAME NAME TEXTAREA, THE VALIDATION WON'T WORK -->


</fieldset>


<?php ActiveForm::end() ?>



I hope this will help some.

Hi, this will answer your questions: decode textarea