How to have both a default value and a set value in codeigniter forms?

codeigniter, default-value, forms, helper

Solution

You can set a default if the value is empty.

From the codeigniter site:

set_value()

Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a default value for the form. Example:

<input type="text" name="job_position" value="<?php echo set_value('job_position', '12'); ?>" size="50" />

The above form will show "12" when loaded for the first time.

Problem

I have a form in codeigniter and would like to have a default value for my input as well as the set_value(). This is my input: ``` echo form_input('job_position',set_value('job_position')); ``` I have a set value in place and working but how can I add a default value of '12'?

Original source