Answers.Body: <p>Please take a look at the <a href="https://docs.craftcms.com/v2/dropdown-fields.html#templating" rel="nofollow noreferrer">docs</a> it's the same in PHP as in Twig</p>
  
  <pre><code>foreach($entry-&gt;getFieldValue('publishOnMobileApp')-&gt;options as $option){
      if($option-&gt;selected){
           // $option-&gt;label is selected
      }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-04T12:35:34.317Z
Answers.LastActivityDate: 2018-05-04T12:35:34.317Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I am trying to get a custom field value on <code>entries.onBeforeSaveEntry</code>, event.  So I can perform some action depending on the value of that field.  </p>
  
  <pre><code>craft()-&gt;on('entries.onBeforeSaveEntry', function(Event $event)
  {
      $entry = $event-&gt;params['entry'];
      $entry-&gt;publishOnMobileApp;  //publishOnMobileApp is the field handle
  });
  </code></pre>
  
  <p>Now this line.</p>
  
  <pre><code>$entry-&gt;publishOnMobileApp;
  </code></pre>
  
  <p>Returns </p>
  
  <pre><code>Craft\MultiOptionsFieldData Object ( 
      [_options:Craft\MultiOptionsFieldData:private] =&gt; 
  Array ( [0] =&gt; Craft\OptionData Object 
  ( 
      [label] =&gt; Yes [value] =&gt; yes [selected] =&gt; )
  )
     [storage:ArrayObject:private] =&amp;gt; Array()
  )
  </code></pre>
  
  <p>I am not sure how exactly I can access just the value of the field (which is "yes" in this case) so I can perform a check.</p>
  
Tags: <custom-field>
Title: Get custom field value on entries.onBeforeSaveEntry event
ThreadText: # Get custom field value on entries.onBeforeSaveEntry event
  
  (Asked by: username_0 on 2018-05-04)
  
  I am trying to get a custom field value on `entries.onBeforeSaveEntry`, event. So I can perform some action depending on the value of that field.
  
  ```
  craft()->on('entries.onBeforeSaveEntry', function(Event $event)
  {
      $entry = $event->params['entry'];
      $entry->publishOnMobileApp;  //publishOnMobileApp is the field handle
  });
  
  ```
  
  Now this line.
  
  ```
  $entry->publishOnMobileApp;
  
  ```
  
  Returns
  
  ```
  Craft\MultiOptionsFieldData Object ( 
      [_options:Craft\MultiOptionsFieldData:private] => 
  Array ( [0] => Craft\OptionData Object 
  ( 
      [label] => Yes [value] => yes [selected] => )
  )
     [storage:ArrayObject:private] =&gt; Array()
  )
  
  ```
  
  I am not sure how exactly I can access just the value of the field (which is "yes" in this case) so I can perform a check.
  
  **Tags:** custom-field
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-04. Score: 1 | Accepted answer
  
  Please take a look at the [docs](https://docs.craftcms.com/v2/dropdown-fields.html#templating) it's the same in PHP as in Twig
  
  ```
  foreach($entry->getFieldValue('publishOnMobileApp')->options as $option){
      if($option->selected){
           // $option->label is selected
      }
  }
  
  ```
  
  
  ---
  
  