Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
PHP check value of CheckBox?

I have 10 checkboxes, like so

<input type="hidden" name="box1" value="0"><input type="checkbox" id="box1" name="box1" value="1">
<input type="hidden" name="box2" value="0"><input type="checkbox" id="box2" name="box2" value="1">
<input type="hidden" name="box3" value="0"><input type="checkbox" id="box3" name="box3" value="1">

and so forth. These checkboxes are all inside a form, and when submitted will go to a PHP script. How am I able to access the values (on or off) for each one. So far I have tried using this:

<input type="hidden" name="box[]" value="0"><input type="checkbox" id="box1" name="box[]" value="1">
<input type="hidden" name="box[]" value="0"><input type="checkbox" id="box2" name="box[]" value="1">
<input type="hidden" name="box[]" value="0"><input type="checkbox" id="box3" name="box[]" value="1">

with

$x = $_POST["box"];
foreach ($x as $y){
    echo $y . "</br>";
}

But this gives random, inaccurate results (say for example box 1, 3 and 4 are clicked, it may give something like this: [0, 0, 0, 1, 1, 0, 0, 1], with 1 being on and 0 off). Can anyone give me a hint in the right direction? Thank you in advance

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can check if a checkbox has been checked by using isset($_POST['checkbox_name']) which returns true if it is checked and false if it is not.

For example;

if(isset($_POST['box1'])){
  //do something positive
}

I do not think you need the other hidden fields.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!