Answers.Body: <p>Two suggestions:</p>
  
  <ol>
  <li><p>Do the setting in setDefaultValues() instead of buildQuickForm().</p></li>
  <li><p>I find the "form data received by postProcess" often contains duplicates and miscellaneous other stuff and I'm sometimes not sure what to look at but usually use $this->_submitValues for visible fields. What are you examining?</p></li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-06T15:40:15.423Z
Answers.Text: that did it - thanks! I get the values from $this->controller->exportValues($this->_name), which I think I just ripped from the wiki somewhere. Seems to be ok.
Answers.UserDisplayName: Andrew West
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T08:20:06.337Z
Answers.LastActivityDate: 2016-01-29T08:20:06.337Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>I always use the setDefaultValues() to add values to my form fields and boxes, like so:</p>
  
  <pre><code>function setDefaultValues() {
      $defaults = array();
      foreach ($this-&gt;_monthlyPattern as $number =&gt; $percentage) {
        $defaults['month'.$number] = $percentage;
      }
      return $defaults;
    }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T10:09:00.297Z
Answers.LastActivityDate: 2016-01-29T10:09:00.297Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>I'm trying to build a form using QuickForm checkboxes. Here's what should happen:</p>
  
  <ol>
  <li>The form displays a bunch of checkboxes. These are ticked or unticked according to a load of API calls in buildQuickForm(). If ticked, this is set using setChecked->true.</li>
  <li>The user then ticks or unticks appropriately, and postProcess() handles the changes.</li>
  </ol>
  
  <p>Except, the form data received by postProcess() is wrong: if a checkbox is set as ticked using setChecked->true, it always comes through as ticked, even if the user unticked it.</p>
  
  <p>I assume I'm not understanding Civi's <a href="http://wiki.civicrm.org/confluence/display/CRMDOC42/QuickForm+Reference" rel="nofollow">QuickForm process</a> properly. Could setChecked->true be kicking in after the form is submitted? During validation, or something?</p>
  
  <p>Any advice appreciated...</p>
  
  <p>Andrew</p>
  
Tags: <quickform>
Title: Why are my QuickForm checkboxes always ticked, in postProcess()?
ThreadText: # Why are my QuickForm checkboxes always ticked, in postProcess()?
  
  (Asked by: username_0 on 2016-01-28)
  
  I'm trying to build a form using QuickForm checkboxes. Here's what should happen:
  
  1. The form displays a bunch of checkboxes. These are ticked or unticked according to a load of API calls in buildQuickForm(). If ticked, this is set using setChecked->true.
  2. The user then ticks or unticks appropriately, and postProcess() handles the changes.
  
  Except, the form data received by postProcess() is wrong: if a checkbox is set as ticked using setChecked->true, it always comes through as ticked, even if the user unticked it.
  
  I assume I'm not understanding Civi's [QuickForm process](http://wiki.civicrm.org/confluence/display/CRMDOC42/QuickForm+Reference) properly. Could setChecked->true be kicking in after the form is submitted? During validation, or something?
  
  Any advice appreciated...
  
  username_0
  
  **Tags:** quickform
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-01-29. Score: 1 | Accepted answer
  
  Two suggestions:
  
  1. Do the setting in setDefaultValues() instead of buildQuickForm().
  2. I find the "form data received by postProcess" often contains duplicates and miscellaneous other stuff and I'm sometimes not sure what to look at but usually use $this->\_submitValues for visible fields. What are you examining?
  
  > **Comments:**
  > **username_0**: that did it - thanks! I get the values from $this->controller->exportValues($this->_name), which I think I just ripped from the wiki somewhere. Seems to be ok.  
  
  ---
  
  ### Answer by username_2 on 2016-01-29. Score: 1
  
  I always use the setDefaultValues() to add values to my form fields and boxes, like so:
  
  ```
  function setDefaultValues() {
      $defaults = array();
      foreach ($this->_monthlyPattern as $number => $percentage) {
        $defaults['month'.$number] = $percentage;
      }
      return $defaults;
    }
  
  ```
  
  
  ---
  
  