CodeIgniter Forums
Multiselect Dropdown validation [Solved- Me Stupid :) ] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Multiselect Dropdown validation [Solved- Me Stupid :) ] (/showthread.php?tid=19010)

Pages: 1 2 3


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]xpix[/eluser]
HI,

I created a multi select dropdown menu and used

Code:
$this->form_validation->set_rules('programs[]', 'Programs', 'trim|required|xss_clean');

for validation.

The problem is that if nothing is selected the browser doesn't send a value via POST.
It seems that CI's validation rule does not work if a POST value is not found.

Am I correct?


Thx


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]tkyy[/eluser]
if there is no post value found it will use the default value which you can optionally supply in the third arg of the set_value function.


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]Dam1an[/eluser]
[quote author="tkyy" date="1243275420"]if there is no post value found it will use the default value which you can optionally supply in the third arg of the set_value function.[/quote]

Don't you mean second param? Tongue


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]xpix[/eluser]
Code:
<div class="formrow">
&lt;?= form_label('Programs: ', 'programs') . form_dropdown('programs[]',$programs_list,$programs_list_selected,'size="5"');?&gt;

&nbsp;&nbsp; <em>Select Multiple</em>

</div>

This is what I use. How do I use set_value in this case?


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]TheFuzzy0ne[/eluser]
I've never heard of this problem before, but in the meantime, I'd recommend you create a custom validation function for your select box, and see if that helps. If not, it should help you debug the problem a bit better.

CodeIgniter loops through the rules and grabs the data accordingly, it doesn't loop through the $_POST array directly. This means that every validation function for any given field is run in sequence until one fails. In your case, it should be failing on 'required'.

Just out of interest, does it make any difference if you put the 'required' rule before the trim? It makes sense that you only trim it once you've confirmed there's actually something to trim.


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]tkyy[/eluser]
[quote author="Dam1an" date="1243275533"][quote author="tkyy" date="1243275420"]if there is no post value found it will use the default value which you can optionally supply in the third arg of the set_value function.[/quote]

Don't you mean second param? Tongue[/quote]

yes!


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]xpix[/eluser]
@TheFuzzy0ne

I changed the order. NO change. Here is the code again

Code:
...
$this->form_validation->set_rules('name', 'Name', 'required|trim|xss_clean');
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
            $this->form_validation->set_rules('pass', 'Password', 'trim|required|min_length[6]');
            $this->form_validation->set_rules('programs[]', 'Programs', 'required|trim|xss_clean');
            
                if ($this->form_validation->run() == FALSE){
            
            }else{
...


Code:
<div class="formrow">&lt;?= form_label('Name: ', 'name') . form_input('name');?&gt;</div>
    <div class="formrow">&lt;?= form_label('Email: ', 'email') . form_input('email');?&gt;</div>
    <div class="formrow">&lt;?= form_label('Password', 'pass') . form_input('pass');?&gt;</div>
    <div class="formrow">&lt;?= form_label('Programs: ', 'programs') . form_dropdown('programs[]',$programs_list,'','size="5"');?&gt;&nbsp;&nbsp; <em>Select Multiple</em></div>
    <div class="formrowsubmit">&lt;?= form_submit('submit', 'Add');?&gt;</div>



Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]TheFuzzy0ne[/eluser]
Ooh, I like invisible code. It's my favourite. Big Grin


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]tkyy[/eluser]
LOL


Multiselect Dropdown validation [Solved- Me Stupid :) ] - El Forum - 05-25-2009

[eluser]Dam1an[/eluser]
[quote author="TheFuzzy0ne" date="1243276010"]Ooh, I like invisible code. It's my favourite. Big Grin[/quote]

I thought your favourite kind was the one that makes coffee for you (invisible coffee or not)