views:

22

answers:

1

Hello

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?

Thanks :)

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.

+3  A: 

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')); ?>"  />
bradym
Ah yes, I just figured this out...by reading the documentation. Probably should do that first in future. http://codeigniter.com/user_guide/helpers/form_helper.html Thanks for your reply brabym.
Robimp