Welcome Guest, Not a member yet? Register   Sign In
Validation - No duplicated items for the dropdown box
#1

[eluser]cinewbie81[/eluser]
I have 3 dropdown box. Each of them have the same items and values in it as shown following:

Code:
$options = array(
                   'RND'  => 'Research AND Development',
                   'HR'    => 'Human Resources',
                   'SALES'   => 'Sales',
                 );

echo form_dropdown('department_1', $options, 'RND');


$options = array(
                   'RND'  => 'Research AND Development',
                   'HR'    => 'Human Resources',
                   'SALES'   => 'Sales',
                 );

echo form_dropdown('department_2', $options, 'HR');


$options = array(
                   'RND'  => 'Research AND Development',
                   'HR'    => 'Human Resources',
                   'SALES'   => 'Sales',
                 );

echo form_dropdown('department_3', $options, 'SALES');

How can i do for the validation part to ensure that there's no duplicated selection of Department ? For eg: HR department can only selecte once from those 3 dropdown box.

Thanks in advance
#2

[eluser]souto[/eluser]
I have the same exact problem, funny.
I'm trying to develop a solution using the Validation class and the solution given here http://ellislab.com/forums/viewthread/63111/

I'll be sure to let you know when I finish it.
#3

[eluser]Michael Wales[/eluser]
Code:
$array = array($this->input->post('department_1'));

if (!in_array($this->input->post('department_2'), $array)) {
  $array[] = $this->input->post('department_2');
} else {
  return FALSE;
}

if (!in_array($this->input->post('department_3'), $array)) {
  $array[] = $this->input->post('department_3');
} else {
  return FALSE;
}

return $array;

That could be cleaned up quite a bit - but you get the point.
#4

[eluser]souto[/eluser]
Thanks, that helped.




Theme © iAndrew 2016 - Forum software by © MyBB