<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>

CC BY-SA 4.0
2018-05-04T12:35:34.317Z
2018-05-04T12:35:34.317Z
Robin Schambach
<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>

<custom-field>
Get custom field value on entries.onBeforeSaveEntry event
# 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] => 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 it's the same in PHP as in Twig
foreach($entry->getFieldValue('publishOnMobileApp')->options as $option){
    if($option->selected){
         // $option->label is selected
    }
}


---

