Answers.Body: <p>If I understand correctly you're talking about a Checkboxes field type. Because you can have multiple checkboxes within such a field, Craft stores an array to the database.</p>
  
  <p>Try if this works:</p>
  
  <pre><code>$entry-&gt;setContentFromPost(array(
      'agreeToTerms' =&gt; array(
          craft()-&gt;request-&gt;getPost('fields.agreeToTerms'),
      )
  ));
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-22T01:35:59.007Z
Answers.Text: Thank you both! I knew I needed to pass an array I think I tried every version of `agreeToTerms[]` I could think of...except this one.
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-21T22:28:21.947Z
Answers.LastActivityDate: 2016-01-22T14:28:48.940Z
Answers.LastEditDate: 2016-01-22T14:28:48.940Z
Answers.UserDisplayName: carlcs
Body: <p>I have a plugin that is listening for a form submit.
  Within that form are two fields <code>firstName</code> and <code>agreeToTerms</code>.</p>
  
  <p>When the form is submitted, I am updating an existing entry with the values that were posted.</p>
  
  <p>I can get all fields to update except my checkbox. I'm not sure what I need to send to craft if the user has checked the checkbox.</p>
  
  <p>Here is what I have so far:</p>
  
  <p><strong>MyController</strong></p>
  
  <pre><code>$postDateTime = ...
  
  ...
  $entry-&gt;setContentFromPost(array(
      'agreeToTerms' =&gt; craft()-&gt;request-&gt;getPost('fields.agreeToTerms'),
      'firstName' =&gt; craft()-&gt;request-&gt;getPost('fields.electronicSignature'),
      'signatureDate' =&gt; $postDateTime
  ));
  ...
  </code></pre>
  
  <p>This returns "1" which is the value of the checkbox.</p>
  
  <pre><code>craft()-&gt;request-&gt;getPost('fields.agreeToTerms') // returns 1
  </code></pre>
  
  <p>But that isn't what I need to send to Craft. If I were using jquery, I am looking for something like</p>
  
  <pre><code>$.prop('checked', true);
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>To help clarify in case someone else comes across this thread, as @carlcs stated I was in fact talking about a checkbox field. </p>
  
  <p>The plugin I am using allows users to create entries in a section. When an entry is created, one of the fields is a checkbox. I was attempting to set the checkbox field as checked if the user had checked the corresponding checkbox when the entry was created.</p>
  
Tags: <plugin-development>
Title: How can I update a checkbox from a plugin?
ThreadText: # How can I update a checkbox from a plugin?
  
  (Asked by: username_0 on 2016-01-21)
  
  I have a plugin that is listening for a form submit.
  Within that form are two fields `firstName` and `agreeToTerms`.
  
  When the form is submitted, I am updating an existing entry with the values that were posted.
  
  I can get all fields to update except my checkbox. I'm not sure what I need to send to craft if the user has checked the checkbox.
  
  Here is what I have so far:
  
  **MyController**
  
  ```
  $postDateTime = ...
  
  ...
  $entry->setContentFromPost(array(
      'agreeToTerms' => craft()->request->getPost('fields.agreeToTerms'),
      'firstName' => craft()->request->getPost('fields.electronicSignature'),
      'signatureDate' => $postDateTime
  ));
  ...
  
  ```
  
  This returns "1" which is the value of the checkbox.
  
  ```
  craft()->request->getPost('fields.agreeToTerms') // returns 1
  
  ```
  
  But that isn't what I need to send to Craft. If I were using jquery, I am looking for something like
  
  ```
  $.prop('checked', true);
  
  ```
  
  **EDIT**
  
  To help clarify in case someone else comes across this thread, as @username_1 stated I was in fact talking about a checkbox field.
  
  The plugin I am using allows users to create entries in a section. When an entry is created, one of the fields is a checkbox. I was attempting to set the checkbox field as checked if the user had checked the corresponding checkbox when the entry was created.
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-21. Score: 0 | Accepted answer
  
  If I understand correctly you're talking about a Checkboxes field type. Because you can have multiple checkboxes within such a field, Craft stores an array to the database.
  
  Try if this works:
  
  ```
  $entry->setContentFromPost(array(
      'agreeToTerms' => array(
          craft()->request->getPost('fields.agreeToTerms'),
      )
  ));
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you both! I knew I needed to pass an array I think I tried every version of `agreeToTerms[]` I could think of...except this one.  
  
  ---
  
  