简体   繁体   English

set_gnue中的set_value()默认值

[英]set_value() default in CodeIgniter

I've used formigniter to generate a form for CI. 我使用formigniter为CI生成表单。 http://formigniter.org/ http://formigniter.org/

That bit works great. 这一点很有效。 However I want to set a default value for the name field. 但是,我想为名称字段设置默认值。

The input code looks like this: 输入代码如下所示:

<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'); ?>"  />

and I'd want to add in the first name with $this->session->userdata('current_client'); 我想用$this->session->userdata('current_client');添加名字$this->session->userdata('current_client');

Will it break my database insert if I just drop it into the set_value function? 如果我将它放入set_value函数,它会破坏我的数据库插入吗?

Edit: 编辑:

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. 我希望使用会话cookie中的名称自动填写名称字段。

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. set_value函数只设置值,使用它的唯一好处是它在重新显示表单时简化了将值设置为已提交的值,或者在表单尚未提交时显示默认值。

This would use the session var as the default value for the form field: 这将使用session var作为表单字段的默认值:

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

Same case with I case 与我的情况相同的情况

$data = array(
    'name' => 'qty_' . $i, 
    'size'=>15, 
    'id' => 'qty_' . $i,
    'required'=>'required', 
    'class'=>'input-small',
    'value' => set_value('qty_' . $i),
    $restock_thirty
);

echo form_input($data);

在codeigniter中如果在控制器sode中生成错误,则假设用户名为unfield然后返回错误但页面可以刷新,则set_value可以设置该文本框值

<input type="text" name="username" placeholder="Username.." value="<?php echo set_value('username') ?>" class="form-control tx">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM