set_value()在CodeIgniter中的默认值 [英] set_value() default in CodeIgniter

查看:72
本文介绍了set_value()在CodeIgniter中的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用formigniter为CI生成表单。 http://formigniter.org/

I've used formigniter to generate a form for CI. http://formigniter.org/

该位有效大。但是我想为名称字段设置默认值。

That bit works great. However I want to set a default value for the name field.

输入代码如下:

<label for="forename">Forename</label>
<?php echo form_error('forename'); ?>
<br /><input id="forename" type="text" name="forename" maxlength="255" value="<?php echo set_value('forename'); ?>"  />

,我想用 $ this-添加名字> session-> userdata('current_client');

如果我将其插入到set_value函数中,将破坏数据库插入?

Will it break my database insert if I just drop it into the set_value function?

编辑:

对不起,我认为我不太清楚那里。我希望使用会话cookie中的名称自动填充名称字段。

Sorry I don't think I was very clear there. I want the name field to be automatically filled in with the name from the session cookie.

推荐答案

只要您正确在运行查询之前转义输入数据,这不会引起任何问题。 set_value函数只是设置值,使用它的唯一好处是,它简化了在重新显示表单时将值设置为已提交的值,或在尚未提交表单时显示默认值的情况。

As long as you're properly escaping input data before running the query, it shouldn't cause any problems. The set_value function just sets the value, the only benefit to using it is it simplifies setting the value to an already submitted value when redisplaying the form or showing a default value when the form has yet to be submitted.

这将使用会话var作为表单字段的默认值:

This would use the session var as the default value for the form field:

<input id="forename" type="text" name="forename" maxlength="255" value="<?php echo set_value('forename', $this->session->userdata('current_client')); ?>"  />

这篇关于set_value()在CodeIgniter中的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆