How to check if at least 1 checkbox has been selected?

Asked

Viewed 127 times

2

            $carrosbr = $_POST['carrosbr'];
            $carrosin = $_POST['carrosin'];
            $corp = $_POST['corp'];
            $houses = $_POST['houses'];
            $vip = $_POST['vip'];
            $skins = $_POST['skins'];
            $guns = $_POST['guns'];
            $bases = $_POST['bases'];
            $eventos = $_POST['eventos'];
            $drift = $_POST['drift'];
            $rpg = $_POST['rpg'];
            $mtmt = $_POST['mtmt'];
            $dayz = $_POST['dayz'];

I have the variables above, they’re all checkboxes. And I need to check that at least one of them is selected.

Help there!

2 answers

2


With this you check each one. And you can do what you want next.

if(isset($_POST['carrosbr'])) //faça algo
if(isset($_POST['carrosin'])) //faça algo
if(isset($_POST['corp'])) //faça algo
if(isset($_POST['houses'])) //faça algo
if(isset($_POST['vip'])) //faça algo
if(isset($_POST['skins'])) //faça algo
if(isset($_POST['guns'])) //faça algo
if(isset($_POST['bases'])) //faça algo
if(isset($_POST['eventos'])) //faça algo
if(isset($_POST['drift'])) //faça algo
if(isset($_POST['rpg'])) //faça algo
if(isset($_POST['mtmt'])) //faça algo
if(isset($_POST['dayz'])) //faça algo
  • Actually, I was able to do it by array. I put everything in an array, and then used the in_array function to check if there was TRUE in the checkboxes. Even so, thanks a lot

0

Using array, you could even filter:

if(filter_input_array(INPUT_POST)

in a row, you would treat all $_POST

Browser other questions tagged

You are not signed in. Login or sign up in order to post.