Reputation: 698
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 first 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.
Upvotes: 3
Views: 46506
Reputation: 469
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">
Upvotes: 0
Reputation: 1
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);
Upvotes: 0
Reputation: 4961
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')); ?>" />
Upvotes: 8