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'?
Simply check if the value exists and use it as the default, otherwise it's blank (or a different default). In the Controller, decide if you're going to load a blank form, if not, send the data for the fields.... $data['fieldname'] = "whatever"; // from the database $this->load->view('yourpage', $data);
form_multiselect() Lets you create a standard multiselect field. The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value or values you wish to be selected.
On the Tools menu, click Form Options. Click Advanced in the Category list, and then click Edit Default Values. In the Edit Default Values dialog box, select the field whose default value you want to set.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With