Validating form dropdown in CodeIgniter
        Posted  
        
            by Gaz
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Gaz
        
        
        
        Published on 2010-03-14T13:22:11Z
        Indexed on 
            2010/03/14
            13:25 UTC
        
        
        Read the original article
        Hit count: 1097
        
Hi,
I am using CodeIgniter's form helper and form validation library to build my forms. I'm having trouble making the dropdown 'sticky' and also finding appropriate validation rules.
This is how I'm populating the drodown:
foreach($events as $event){
$options[$event->event_title] = $event->event_title;
}
$firstItem = '<option>Please select one...</option>';
echo form_dropdown('events', $options, '', $firstItem);
This is building the options from events stored in the database. The form looks fine and is populating tall the fields correctly.
Hwoever, when I come to submit the form, the dropdown isn't holding onto the value selected? Also, how should I validate it, I want to make it required but I also want to make sure that I dont except the first option in the dropdown 'Please select one...'
Thanks in advance.
Cheers, Gaz
© Stack Overflow or respective owner