开发者

Convenient way to populate fields in codeigniter

Codeigniter has a very convenient way to repopulate the field on validation failure

set_value()

In my app I want allow user to edit the entity usin开发者_如何学运维g the same form I use to create it. But I cannot use set_value() to populate the fields while the form is in editing mode.

I there any convenient way to do it.

Thanks.


You give set_value() a second parameter that will be its initial value on loading.

I generally do this using a @ to supress errors if the piece of data does not exist

set_value('input_name',@$input_value);

for this, the form element will be prefilled with $input_value if it exists


You should use set_value. I don't see how you would get an error using set_value when editing.

set_value has a second parameter, which lets you put in the default value, which in your case is the value from the database:

<input type="text" name="first_name" value="<?php echo set_value('first_name', $row->first_name);?>">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜