开发者

set_value() default in CodeIgniter

开发者 https://www.devze.com 2023-01-18 19:20 出处:网络
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.

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.

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 fir开发者_开发百科st name with $this->session->userdata('current_client');

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

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.


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.

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


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);


In CodeIgniter, if generate an error in controller code suppose username unfilled then return an error but the page can refresh, then set_value can set that text box value

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

精彩评论

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