Skip to content

Bug: Multiple select validation problem #2757

Description

@pbquet

Hello,
I try to validate a form with a multiple select that was working in CI3

In my view:

<select name="id_user[]"  multiple="">
<option value="1">user1</option>
<option value="2">user2</option>
<option value="3">user3</option>
</select>

In my controller :

echo '<pre>' , var_dump($_POST) , '</pre>';

print

array(2) {
["id_user"]=>
array(2) {
[0]=> string(1) "1"
[1]=> string(1) "2"
}
["find"]=> string(10) "find"
 }

AND

$this->validation->setRules([
    'id_user[]'=>'numeric',
]);
$this->validation->withRequest($this->request)->run();
echo '<pre>' , var_dump($this->validation->getErrors()) , '</pre>';

print

array(1) {
  ["id_user[]"]=>  string(46) "The id_user[] field must contain only numbers."
}

it looks like CodeIgniter\Validation\run() is looking for "id_user[]" in the $_POST wich doesn't exist, instead of "id_user". And if I change the rule to 'id_user'=>'numeric', it does't care about the multiple value ...
is it a bug or do I have to change something in my code ?

Context

  • CodeIgniter 4.02
  • Windows 10
  • PHP version 7.3.15

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions