Welcome Guest, Not a member yet? Register   Sign In
Empty value dropdown
#1

[eluser]Michal1[/eluser]
Hi guys,

what is the easiest and best way to have an empty value in dropdown? I am using dropdown boxes for searching but cannot get an empty value.

In controller in one function I have:

Code:
$data['color'] = array(
  'red'=>'blue',
  'blue'=>'blue'
  );

I passed this into view and then in view have something like:

Code:
<?php echo form_dropdown('dropdown_colors',$color,'red');

and then I use dropdown for searching in db. I use my model for this and db function where. So something like:

Code:
$this->db->where('colors',$sent_parameter);
etc etc etc

Everything works fine but now I want to insert empty value into that dropdown which will used when user doesnt want to use this specific dropdown during search.

So what is the best way how to do that? I thought I could edit that array little bit like:

Code:
$data['color'] = array(
  'empty'=>'empty',
  'red'=>'blue',
  'blue'=>'blue'
  );

and then in model I would check if returned value is not 'empty' and if not then I can use db->where because I know user chose something. Is it right approach? Thank you




Theme © iAndrew 2016 - Forum software by © MyBB