title: How do I check if checkbox is checked in PHP?
body: <p>I am trying to check if a checkbox have been checked in PHP in order to register. But it's not working right now. This is the code I am using so far, to check if it have been checked.</p>
  
  <pre><code>if(!isset($_POST['tos']))
    $this-&gt;errors[] = 'Please accept our Terms of Service.';
  </code></pre>
  
  <p>And this is the HTML code.</p>
  
  <pre><code>&lt;div class="checkbox"&gt;
  &lt;label&gt;
  &lt;input type="checkbox" name="tos" value="0"&gt; I agree to the &lt;a href="#"&gt;Terms of Service&lt;/a&gt; and &lt;a href="#"&gt;Privacy Policy&lt;/a&gt;
  &lt;/label&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Full form code:</p>
  
  <pre><code>        &lt;form role="form" method="POST" action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;"&gt;
                &lt;div class="form-group"&gt;
  
                &lt;div class="row"&gt;
                    &lt;div class="col-sm-6"&gt;
                    &lt;label for="firstname"&gt;Firstname&lt;/label&gt;
                    &lt;input type="text" class="form-control" id="firstname" name="firstname" placeholder="Firstname"&gt;
                    &lt;/div&gt;
                    &lt;div class="col-sm-6"&gt;
                    &lt;label for="surname"&gt;Surname&lt;/label&gt;
                    &lt;input type="text" class="form-control" id="surname" name="surname" placeholder="Surname"&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;label for="username"&gt;Username&lt;/label&gt;
                  &lt;input type="text" class="form-control" id="ruser" name="ruser" placeholder="Username"&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;label for="email2"&gt;Email address&lt;/label&gt;
                  &lt;input type="email" class="form-control" id="remail" name="remail" placeholder="Enter email"&gt;
                &lt;/div&gt;
                &lt;div class="form-group"&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="col-sm-6"&gt;
                    &lt;label for="password2"&gt;Password&lt;/label&gt;
                    &lt;input type="password" class="form-control" id="rpass" name="rpass" placeholder="Password"&gt;
                    &lt;/div&gt;
                    &lt;div class="col-sm-6"&gt;
                    &lt;label for="password2"&gt;Repeat password&lt;/label&gt;
                    &lt;input type="password" class="form-control" id="rpass2" name="rpass2" placeholder="Password"&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="checkbox"&gt;
                  &lt;label&gt;
                    &lt;input type="checkbox" name="tos" value="0"&gt; I agree to the &lt;a href="#"&gt;Terms of Service&lt;/a&gt; and &lt;a href="#"&gt;Privacy Policy&lt;/a&gt;
                  &lt;/label&gt;
                &lt;/div&gt;
                 &lt;input type="hidden" name="secur" value="&lt;?php echo $ip;?&gt;"/&gt;
                 &lt;input type="hidden" name="token" value="&lt;?php echo $token;?&gt;"/&gt;
                &lt;button type="submit" name="register" class="btn btn-block btn-color btn-xxl"&gt;Create an account&lt;/button&gt;
              &lt;/form&gt;
  </code></pre>
  
  <p>What's wrong with this code? Any help would be appreciated.</p>