title: Joomla PHP: Checkbox won't uncheck
body: <p>Making a simple component.  If I save a new record with the box checked, it saves fine.  If I go back and uncheck a previously checked item it reverts back to checked.  I thought it had something to do with a hidden field, played with putting one of those in manually but that didn't fix it either so took it out. </p>
  
  <p>Here's where I'm at:
    An xml snippet:</p>
  
  <pre><code>&lt;fieldset name="checks"&gt;
    &lt;field name="checkbox1"
      type="checkbox"
      label="First Checkbox"
      value="1"
      filter="intval"         
    /&gt; 
  
     &lt;field name="checkbox2"
      type="checkbox"
      label="Second Checkbox"
      value="1"
      filter="intval"         
    /&gt; 
  
   ...
  
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>The edit.php file:</p>
  
  <pre><code>&lt;div class="width-45 fltlft"&gt;
    &lt;fieldset class="adminform"&gt;
      &lt;legend&gt;Checkboxes&lt;/legend&gt;
      &lt;ul class="adminformlist"&gt;
        &lt;?php foreach ($this-&gt;form-&gt;getFieldset('checks') as $field): ?&gt;
          &lt;li&gt;
            &lt;?php echo $field-&gt;label; ?&gt;
            &lt;?php echo $field-&gt;input; ?&gt;
          &lt;/li&gt;
        &lt;?php endforeach ?&gt;
      &lt;/ul&gt;
    &lt;/fieldset&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Also added this towards the end before the form.token:</p>
  
  <pre><code>&lt;input type="hidden" name="task" id="task" value="completion.edit" /&gt;
  </code></pre>
  
  <p>I tried deleting the value="1" in the xml but then I had the opposite problem where the check wouldn't save at all.</p>
  
  <p>Any ideas?  </p>
  
  <p>Thanks!</p>
  
  <p>=============================</p>
  
  <p>Edit:</p>
  
  <p>Model:</p>
  
  <pre><code>&lt;?php
  defined( '_JEXEC' ) or die;
  
  jimport('joomla.application.component.modeladmin');
  
  class AssessModelCompletion extends JModelAdmin
  {
  //tells it what kind of record and the prefix
  
      public function getTable($type = 'Completion', $prefix = 'AssessTable', $config = array())
      {
          return JTable::getInstance($type, $prefix, $config);
      }
  
      //Load the data into the edit form
      protected function loadFormData()
      {
          $data = JFactory::getApplication()-&gt;getUserState('com_assess.edit.completion.data', array()); //first try to get the data from the session, not db
  
          if (empty($data)) {
              $data = $this-&gt;getItem(); //this gets the data
          }
  
          return $data;
  
      }
  
      //Stores data in a session in case a field is missed
      public function getForm($data = array(), $loadData = true)
      {
          $form = $this-&gt;loadForm('com_assess.completion', 'completion', array('control' =&gt; 'jform', 'load_data' =&gt; $loadData));
  
          return $form;
      }
  }
  </code></pre>
  
  <p>And table:</p>
  
  <pre><code>&lt;?php 
  defined ( '_JEXEC' ) or die;
  
  class AssessTableCompletion extends JTable
  {
      public function __construct(&amp;$db)
      {
          parent::__construct('#__tablename_completions', 'completion_id', $db);
      }
  }
  </code></pre>
  
  <p>======================================</p>
  
  <p>References:
  <a href="https://stackoverflow.com/questions/6964333/joomla-1-6-admin-form-processing-grouped-checkboxes-in-form">https://stackoverflow.com/questions/6964333/joomla-1-6-admin-form-processing-grouped-checkboxes-in-form</a></p>
  
  <p><a href="https://stackoverflow.com/questions/9017599/tutorial-code-is-not-working-any-more-in-joomla-2-5">Tutorial code is not working any more in Joomla 2.5</a></p>
  
  <p><a href="http://docs.joomla.org/Developing_a_Model-View-Controller_%28MVC%29_Component_for_Joomla!1.7_-_Part_09#Adding_a_toolbar" rel="nofollow noreferrer">http://docs.joomla.org/Developing_a_Model-View-Controller_%28MVC%29_Component_for_Joomla!1.7_-_Part_09#Adding_a_toolbar</a></p>