Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Hidden field in yii

I'm trying to place data in hidden text in yii, but I don't know how. I need a similar code to a regular php syntax:

<input type="hidden" name="field_name" value="a"/>

It's supposed to be a field with static value of a. I just need it to go with my $_POST variables for error checking.

Is it possible to avoid modifying the models and controllers just to put the field in?I cant use gii cause I only have snippets of code with me.Sorry as well as I have little understanding of yii so I have no clue if what I'm saying about the last 2 sentences is correct.

like image 271
marchemike Avatar asked Sep 22 '13 13:09

marchemike


3 Answers

in views

hidden field with model and form:

<?php echo $form->hiddenField($model, 'name'); ?>

or without model

<?php echo CHtml::hiddenField('name' , 'value', array('id' => 'hiddenInput')); ?>
like image 182
Developerium Avatar answered Nov 02 '22 19:11

Developerium


Yii hidden input :

<?php echo $form->hiddenField($model,'fieldName',array('value'=>'foo bar')); ?>
like image 10
Alireza Fallah Avatar answered Nov 02 '22 19:11

Alireza Fallah


In Yii2 this has changed too:

<?= Html::activeHiddenInput($model, 'name') ;?>

References:

http://www.yiiframework.com/forum/index.php/topic/49225-activeform-how-do-you-call-label-input-and-errors-individually/

https://github.com/yiisoft/yii2/issues/735

like image 10
Coz Avatar answered Nov 02 '22 18:11

Coz