I am attempting to validate the values of a multiple select form using the IN validation rule. I continue to get the error that my value is incorrect despite being identical to one of the options in the list. I am thinking it has to be the way I am identifying the name in the validator ("step1"). However, I have also used step1., step1.0., step1*. It will keep giving the "Invalid Response" response which corresponds to the IN error.
Controller
public function postQuestionDetailsStep1(Request $request)
{
if ($request->ajax())
{
$step1 = $request->input('step1');
$this->validate($request, [
'step1' => 'required',
'step1.0' => 'in:Less than $50,000,$50,000-$100,000,More than $100,000',
], [
'step1.required' => 'You must choose one.',
'step1.in' => 'Invalid response.',
]);
}
}
View
<input type="checkbox" class="custom-control-input" id="step1-option1" name="step1[]" value="Less than $50,000">
<input type="checkbox" class="custom-control-input" id="step1-option2" name="step1[]" value="$50,000-$100,000">
<input type="checkbox" class="custom-control-input" id="step1-option3" name="step1[]" value="More than $100,000">
Javascript
$('#step-1').submit(function(e) {
e.preventDefault();
var step1 = [];
$("input[name='step1[]']:checked").each(function() {
step1.push($(this).val());
});
$.ajax({
type: "POST",
url: "/question/details/1",
data: {step1:step1},
error: function(data){
},
success: function(data) {
console.log(data);
}
});
});
in:"Less than $50,000","$50,000-$100,000","More than $100,000"? Reference: stackoverflow.com/questions/19575860/…