Hello all!
I'm need validation for a question of the style: "Select your interests in order of preference in the following checkboxes".
I've got the frontend and php all figured out but can't make the validation work. if I var_dump($_POST) I get the following:
Array
(
[_token] => 6vPgIM1MX7MJ0DzMX2OFjCdPEBBel5mRJ6RzrEjR
[11] => Array // Means question id 11
(
[42] => 2 // Means choice id 42 was chosen second
[43] => 1 // Means choice id 43 was chosen first
[44] => 3 // Means choice id 44 was chosen third
)
[12] =>
[13] => Array
(
[4] => 1
)
[btn-validate] => CONTINUE
)
Then my var_dump($validationRules) is like this (simplified, only 3 questions):
Array
(
[11] => Array
(
[0] => between:0,2
)
[12] => Array
(
[0] => between:1,3
)
[13] => Array
(
[0] => between:0,1
)
)
And finally, my var_dump($validationMessages) yields this:
Array
(
[11.between] => You should select between 0 and 2 choices
[12.between] => You should select between 1 and 3 choices
[13.between] => You should select between 0 and 1 choices
)
However when I try validating the input, it's valid with the previous dumps (and is still valid for pretty much anything I put send):
$validator = Validator::make($request->all(), $validationRules, $validationMessages);
if ($validator->fails()) {
var_dump($validator->errors());
exit('fail'); // Never ends up here
}
exit('all good'); // Always ends up here
Am I missing something? How to make the between:x,y validation rule work with an array of values that needs between X and Y selected checkboxes?
Thanks! :)