Welcome Guest, Not a member yet? Register   Sign In
set_value and select boxes
#1

[eluser]tim1965[/eluser]
Hi

I am having a problem with using set_value to pre-populate an update form on the initial load i.e. the initial db lookup to populate the fields. I cannot seem to get any of my select boxes to display the db value.
On the select it defaults to the initial option value, rather than Mr whch is what the query is returning as var $title
Quote:
<select name="title" id="title" value="&lt;?php echo set_value('title',$title); ?&gt;" class="combo">
<option value="">--Please select--</option>
<option value="Mrs"&lt;?php echo set_select('title', 'Mrs'); ?&gt;>Mrs</option>
<option valuwd="Miss"&lt;?php echo set_select('title', 'Miss'); ?&gt;>Miss</option>
<option value="Ms"&lt;?php echo set_select('title', 'Ms'); ?&gt;>Ms</option>
<option value="Mr"&lt;?php echo set_select('title', 'Mr'); ?&gt; >Mr</option>
</select>
Quote:

I have also tried echoing $title directly as a value and this doesnt work.
set_value is working correctly for all fields other than select´s.
I have set validation for these fields as required and this is working correctly for selectds.
Any help appreciated
#2

[eluser]pistolPete[/eluser]
Please post your controller code.
#3

[eluser]tim1965[/eluser]
Ok here it is. I will only post the relevant part which is this first if. If i dump the query i can see the correct data being pulled back from the db.
function update_contact_details()
{
$this->output->enable_profiler(TRUE);

$z=$this->uri->segment(4);
if(isset($z))
{
$p = $this->uri->segment(4);
$this->session->set_userdata('x', $p);

}
else
{
$p = $_POST['propid'];
$this->session->set_userdata('x', $p);
}
$prop = $this->session->userdata('x');
$propid = $prop['x'];


$this->load->model('property_management/M_master_contact_details_v1');

$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Title', 'trim|xss_clean|required|alpha');
$this->form_validation->set_rules('first_name', 'First Name', 'trim|xss_clean|required|max_length[50]|alpha');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|xss_clean|required|max_length[50]|alpha');
$this->form_validation->set_rules('firstlineofaddress', '1st line of Address', 'trim|xss_clean|required|max_length[50]|alpha_dash_space');
$this->form_validation->set_rules('secondlineofaddress', '2nd line of Address', 'trim|xss_clean|max_length[50]|alpha_dash_space');
$this->form_validation->set_rules('townorcity', 'Town or City', 'trim|xss_clean|required|max_length[50]|alpha_dash_space');
$this->form_validation->set_rules('provinceorcounty', 'Province, County or State', 'trim|xss_clean|required|max_length[50]|alpha');
$this->form_validation->set_rules('postcode', 'Post\Zip code', 'trim|xss_clean|required|max_length[15]|alpha_numeric');
$this->form_validation->set_rules('country', 'Country', 'required|max_length[50]|alpha');
$this->form_validation->set_rules('contactnotes', 'Contact Notes', 'trim|xss_clean|required|max_length[300]|alpha_dash_space');
$this->form_validation->set_rules('contactpref', '', '');
$this->form_validation->set_rules('languages', 'languages', '');
$this->form_validation->set_rules('languageother', 'Other language', 'trim|xss_clean|max_length[30]|alpha_dash_space');
$this->form_validation->set_rules('adverttype', 'Type of advert', 'required');
$this->form_validation->set_rules('terms', 'Accept our Terms', 'required');


if ( ! $this->form_validation->run() && $this->validation->error_string == '')
{

$data =$this->M_master_contact_details_v1->get_contact_details($propid);
$data['propid'] = $prop['x'];
$this->load->view('property_management/contact_details/v_contact_details_template_v1',$data);

}
#4

[eluser]verynewtothis[/eluser]
Ok I didn't even know that < select > tag had an attribute by the name of "value" so it was an eye opener for me...
any ways I would try this:

Code:
<select name=“title” id=“title” class=“combo”>
<option value=”“ &lt;?php echo set_select('title' , "", !strcmp($title,"") ? TRUE : FALSE)?&gt;>—Please select—</option>
<option value=“Mrs”&lt;?php echo set_select(‘title’, ‘Mrs’, !strcmp($title,"Mrs") ? TRUE : FALSE); ?&gt;>Mrs</option>
<option valuwd=“Miss”&lt;?php echo set_select(‘title’, ‘Miss’, !strcmp($title,"Miss") ? TRUE : FALSE); ?&gt;>Miss</option>
<option value=“Ms”&lt;?php echo set_select(‘title’, ‘Ms’, !strcmp($title,"Ms") ? TRUE : FALSE); ?&gt;>Ms</option>
<option value=“Mr”&lt;?php echo set_select(‘title’, ‘Mr’, !strcmp($title,"Mr") ? TRUE : FALSE); ?&gt; >Mr</option>      
</select>
#5

[eluser]vigna[/eluser]
Code:
<select name="status" id="status">
                    <option value="">Select Status</option>
                    <option value="unverified" &lt;?php echo set_select('status', "unverified", ("unverified" ==  set_value('status', $user->status))); ?&gt;>Unverified</option>
                    <option value="inactive" &lt;?php echo set_select('status', "inactive", ("inactive" ==  set_value('status', $user->status))); ?&gt;>Inactive</option>
                    <option value="active" &lt;?php echo set_select('status', "active", ("active" ==  set_value('status', $user->status))); ?&gt;>Active</option>
                    </select>

I am using this type for edit form , where the first time the value is filled from the DB and next when the user post back the values,
it fills the post back value instead of the DB value when validation fails..

I am not sure this is the rightway to do it. But it worked!
#6

[eluser]tim1965[/eluser]
Vigna

Went with your option and it worked a treat. Feel the virtual hug. Thanx to both of you for your help.
I am thinking i will be having problems with checkboxes if selects are problematibc. Could i also ask both of you what you do for these, anything special i should know ?? Thsi is my 1st edit/update with CI so would appreciate any help you can give.
Thnx again.
#7

[eluser]tim1965[/eluser]
Dont worry. I looked at it again and realised i can use this for checkboxes as well. Many thanks again for sharing your code.
#8

[eluser]vigna[/eluser]
I am glad that it helped. You're most welcome.
for checkbox, I am following the same as for select. This is what I use
Code:
&lt;input type="checkbox" name="accept_emails" value="yes" &lt;?php echo set_checkbox('accept_emails', "yes", set_value('accept_emails', $user-&gt;accept_emails) == "yes");?&gt; />
and make sure you have a validation rule for the field you want post back values to be filled.
Me too new to codeigniter buddy!




Theme © iAndrew 2016 - Forum software by © MyBB