yii2 hidden input value

Changing the value here doesn't make sense, because it's active field. It means value will be synchronized with the model value.

Just change the value of $model->hidden1 to change it. Or it will be changed after receiving data from user after submitting form.

With using non-active hidden input it will be like that:

use yii\helpers\Html;

...

echo Html::hiddenInput('name', $value);

But the latter is more suitable for using outside of model.


Use the following:

echo $form->field($model, 'hidden1')->hiddenInput(['value'=> $value])->label(false);

simple you can write:

<?= $form->field($model, 'hidden1')->hiddenInput(['value'=>'abc value'])->label(false); ?>