We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

How do I validate multiple checkboxes?

Stephen September 24, 2020 by Stephen

I've got a checkbox group with two checkboxes, I'd like both of them to be checked before the form will submit.

Setting the field as 'required' half works. The form will error if nothing is checked, but it submits if one of the boxes is ticked.

I can see under the validation tab, there's a list of additional rules. But I'm not sure which rule to use.

If it helps, this is what the HTML checkbox group looks like:

    <label>Contact permissions</label>
    <span>Please tick both checkboxes</span>
        <input type="checkbox" name="checkboxes[]" value="gdpr" />
        Please contact me with the details I've provided
        <input type="checkbox" name="checkboxes[]" value="terms" />
        I agree with the <a href="#">terms and conditions</a>

I'm using the {{ fields }} tag to generate the HTML

Under the validation tab, there's a link to the Laravel docs. As I want to validate two checkboxes, I think I need the required_with: rule, but I can't get it to work...

required_with: is looking for two values, the example shows this:


The values of the checkboxes are, value="GDPR" and value="Terms"so I (wrongly) assume this should work...


After saving the changes and testing the form, it still submits? Even though only one of the checkboxes might be ticked...

What is the correct syntax/values to use to get this to work?

>>>>>>> Unanswered <<<<<<<
1 Reply