Welcome Guest, Not a member yet? Register   Sign In
Validation rule required on multiple select field always fails
#1

(This post was last modified: 06-18-2016, 02:56 PM by Nikos_Kontis.)

Hello everyone, 

I don't know if this is a bug or something that I missed in the upgrade guide from CI2 to CI3, but here goes...
My problem is related to validating with the "required" rule a SELECT field that can capture multiple values.

The code I was using until I migrated CI3 seemed to work properly, but after I migrated to CI3 it fails to pass an if no data are being send send from the field. If I remove the required validation rule, the whole logic works properly and the data are saved/updated properly in the database.

HTML:

Code:
<select id="groups" name="groups[]" multiple="multiple" >
   <option value="1">Group A</option>
   <option value="2">Group B</option>
   <option value="3">Group C</option>
   <option value="4">Group D</option>
</select>

and the validation rule in the PHP controller:
PHP Code:
$rules = [        
    [
'field' => 'groups''label' => 'groups''rules' => 'required']
];
$this->form_validation->set_rules($rules);
$validation_result $this->form_validation->run(); 

I appreciate any help or guidance, thanks.
Reply


Messages In This Thread
Validation rule required on multiple select field always fails - by Nikos_Kontis - 06-18-2016, 03:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB