Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'?

like image 852
hairynuggets Avatar asked Jun 08 '12 09:06

hairynuggets


People also ask

How to set default value in codeigniter?

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

Which function in codeigniter is used to set the value of form?

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.

How do I change the default form value?

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.


1 Answers

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.

like image 174
Rooneyl Avatar answered Oct 19 '22 17:10

Rooneyl