Answers.Body: <p>You can pull an array of all the options for a checkbox field by calling <code>getOptions()</code>:</p>
  
  <pre><code>$options = $entry-&gt;storyCategories-&gt;getOptions();
  </code></pre>
  
  <p>Each option will be an object with three properties, <code>label</code>, <code>value</code> and <code>selected</code>. To get all selected options for a field, you can loop through the options and test for the <code>selected</code> property:</p>
  
  <pre><code>$options = $entry-&gt;storyCategories-&gt;getOptions();
  $selectedOptions = array();
  foreach ( $options as $option ) {
      if ( $option-&gt;selected ) {
          $selectedOptions[] = $option;
      }
  }
  </code></pre>
  
  <p><em>Note that this exact code will work for Dropdown, Multi-select and Radio button fields as well.</em></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-07T00:36:47.663Z
Answers.Text: A quick followup question. If I were to make a change to the selected value and push it back into craft via plugin logic, am I storing a json object?
Answers.UserDisplayName: David A McInnis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-07T07:48:29.763Z
Answers.Text: @DavidAaronMcInnis The values are technically stored in the database as a serialized array (see the column ```field_storyCategories``` in the database table ```craft_content```, but as long as you use the [EntriesService](http://buildwithcraft.com/docs/plugins/working-with-elements#saving-elements) there's no JSON involved in the transport, no. If you have any other questions regarding updating entries/fields etc. it would probably be best to create a new question :)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-06T18:50:32.680Z
Answers.LastActivityDate: 2015-04-06T18:57:51.997Z
Answers.LastEditDate: 2015-04-06T18:57:51.997Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I have a checkbox field that is populate with user choices.  I need to get the values they have selected from within a plugin. Here is my attempt. Not working.</p>
  
  <pre><code>    $entry  = craft()-&gt;entries-&gt;getEntryById($entryId, $localeId = null);
      foreach ($entry-&gt;storyCategories-&gt;options as $option) {
       var_dump($option);
      }
  </code></pre>
  
  <p>Can somebody please show me how to get these selected values?</p>
  
Tags: <plugin-development><checkboxes>
Title: Retrieving Checkbox Values from Plugin
ThreadText: # Retrieving Checkbox Values from Plugin
  
  (Asked by: username_0 on 2015-04-06)
  
  I have a checkbox field that is populate with user choices. I need to get the values they have selected from within a plugin. Here is my attempt. Not working.
  
  ```
      $entry  = craft()->entries->getEntryById($entryId, $localeId = null);
      foreach ($entry->storyCategories->options as $option) {
       var_dump($option);
      }
  
  ```
  
  Can somebody please show me how to get these selected values?
  
  **Tags:** plugin-development, checkboxes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-06. Score: 6 | Accepted answer
  
  You can pull an array of all the options for a checkbox field by calling `getOptions()`:
  
  ```
  $options = $entry->storyCategories->getOptions();
  
  ```
  
  Each option will be an object with three properties, `label`, `value` and `selected`. To get all selected options for a field, you can loop through the options and test for the `selected` property:
  
  ```
  $options = $entry->storyCategories->getOptions();
  $selectedOptions = array();
  foreach ( $options as $option ) {
      if ( $option->selected ) {
          $selectedOptions[] = $option;
      }
  }
  
  ```
  
  *Note that this exact code will work for Dropdown, Multi-select and Radio button fields as well.*
  
  > **Comments:**
  > **username_0**: A quick followup question. If I were to make a change to the selected value and push it back into craft via plugin logic, am I storing a json object?  
  > **username_1**: @DavidAaronMcInnis The values are technically stored in the database as a serialized array (see the column ```field_storyCategories``` in the database table ```craft_content```, but as long as you use the [EntriesService](http://buildwithcraft.com/docs/plugins/working-with-elements#saving-elements) there's no JSON involved in the transport, no. If you have any other questions regarding updating entries/fields etc. it would probably be best to create a new question :)  
  
  ---
  
  