Reputation: 9170
I have to validate that maximum 3 checkboxes are clicked. There are 11. How could I do this efficiently and without testing every possible situation?
Upvotes: 1
Views: 153
Reputation: 382656
You can do like this:
if (count($_POST['checkbox_name']) === 3)
{
// your code here.....
}
where your checkbox names should be suffixed with []
eg:
<input type="checkbox" name="checkbox_name[]" value="1" />
<input type="checkbox" name="checkbox_name[]" value="2" />
<input type="checkbox" name="checkbox_name[]" value="3" />
Upvotes: 2