How To Set Default Value In Hidden Filed In Yii2

i want to id store in hidden filed…

m use these two line…

here $id variable set in default value in hidden filed…




<?php 

   

   $id= yii::$app->user->identity->id;

   echo $form->Field($model, 'user_id');

?>



what i can changes in code…

You could do it like this:





<?php

$id= yii::$app->user->identity->id;


echo $form->field($model, 'user_id')

  ->hiddenInput(['value' => $id])

  ->label(false);


?>

But I’m not sure if you really want this. Is $model an new object?

Just set a default value in your model and it will be selected in the form upon loading…

How to hide (not showing) certain field while update…?

if it’s a new model then you can use the BlameableBehavior or make it a rule.




'rules'=>[

'user_id','default','value'=>Yii::$app->user->id

]