<p>The name of your select is <code>regionType</code> thus it will try to store the property <code>regionType</code> in your field. When you call the field <code>value</code> it will set the property <code>value</code> in you class.</p>

<p>You either need to include the property or change it to an existing one.</p>

CC BY-SA 4.0
2018-09-22T16:47:21.673Z
Got it, thanks! Why is it that when I use `settings.regionType` in my template I get a value but when I use `$this->getSettings()->regionType` in my methods I get a `Trying to get property of non-object` error?
kmgdev
CC BY-SA 4.0
2018-09-22T16:51:27.873Z
I'm not sure why you are using `getSettings` to begin with. It will return an array of your properties, so it's the same as `this->regionType` (just a little bit slower). Twig doesn't separate between  array or object syntax, it's the same but in PHP you have a different syntax between arrays and objects
Robin Schambach
CC BY-SA 4.0
2018-09-22T16:57:10.523Z
I think I'm not understanding how to access pre-stored settings for a field. In response to your original answer I just added `public $regionType` to my field class. But how do I grab the stored settings so I can use them to set which options display in the field? If I just use `$this->regionType` then all I get is a null value. I thought `$this->getSettings()` was the way to pull in the stored settings?
kmgdev
CC BY-SA 4.0
2018-09-22T17:07:31.317Z
What are pre-stored settings? Each field has settings that represents certain attributes of the class. When you save a field Craft will serialize your body params and store them as settings in your fields table. When you populate it the next time Yii2 will configure your field class with those attributes that are stored as JSON in your fields table
Robin Schambach
CC BY-SA 4.0
2018-09-22T22:46:34.780Z
Ah, OK I see now. I thought I had to explicitly go and grab the settings properties but they're already pre-loaded for me.
kmgdev
CC BY-SA 4.0
2018-09-22T08:34:37.533Z
2018-09-22T08:39:39.817Z
2018-09-22T08:39:39.817Z
Robin Schambach
<p>I have a custom field with a setting for <code>regionType</code>, but when I try to save the field I get this error:</p>

<blockquote>
  <p>Setting unknown property:
  kgrote\siteutilities\fields\Regionselect::regionType</p>
</blockquote>

<p>In my fieldtype file I have this to load the settings field:</p>

<pre><code>public function getSettingsHtml()
{
    // Render the settings template
    return Craft::$app-&gt;getView()-&gt;renderTemplate(
        'site-utilities/_components/fields/Regionselect_settings',
        [
            'field' =&gt; $this,
            'settings' =&gt; $this-&gt;getSettings()
        ]
    );
}
</code></pre>

<p>And the settings template looks like this:</p>

<pre><code>{% import "_includes/forms" as forms %}

{% set input %}
    {{ forms.select({
        id: 'regionType',
        name: 'regionType',
        options: ({
            'usStates' : 'US States &amp; Canadian Provinces',
            'countries' : 'Countries'
        })
    }) }}
{% endset %}

{{ forms.field(
    {
        label: "Region Type"|t('app')
    }, 
    input 
) }}
</code></pre>

<p>My field is a simple pre-filled dropdown, so I'm importing most of the methods for my field from <code>craft/vendor/craftcms/cms/src/fields/BaseOptionsField.php</code>. </p>

<p>I don't see much in the source code that relates to settings, so I'm not really sure what's causing this error.</p>

<plugin-development><fieldtypes>
Custom Field Settings: Unknown Property Error
# Custom Field Settings: Unknown Property Error

(Asked by: username_0 on 2018-09-21)

I have a custom field with a setting for regionType, but when I try to save the field I get this error:

Setting unknown property:
  kgrote\siteutilities\fields\Regionselect::regionType

In my fieldtype file I have this to load the settings field:
public function getSettingsHtml()
{
    // Render the settings template
    return Craft::$app->getView()->renderTemplate(
        'site-utilities/_components/fields/Regionselect_settings',
        [
            'field' => $this,
            'settings' => $this->getSettings()
        ]
    );
}

And the settings template looks like this:
{% import "_includes/forms" as forms %}

{% set input %}
    {{ forms.select({
        id: 'regionType',
        name: 'regionType',
        options: ({
            'usStates' : 'US States & Canadian Provinces',
            'countries' : 'Countries'
        })
    }) }}
{% endset %}

{{ forms.field(
    {
        label: "Region Type"|t('app')
    }, 
    input 
) }}

My field is a simple pre-filled dropdown, so I'm importing most of the methods for my field from craft/vendor/craftcms/cms/src/fields/BaseOptionsField.php. 
I don't see much in the source code that relates to settings, so I'm not really sure what's causing this error.

**Tags:** plugin-development, fieldtypes


---

## 1 answers

### Answer by username_1 on 2018-09-22. Score: 1 | Accepted answer

The name of your select is `regionType` thus it will try to store the property `regionType` in your field. When you call the field `value` it will set the property `value` in you class.

You either need to include the property or change it to an existing one.

> **Comments:**
> **username_0**: Got it, thanks! Why is it that when I use `settings.regionType` in my template I get a value but when I use `$this->getSettings()->regionType` in my methods I get a `Trying to get property of non-object` error?  
> **username_1**: I'm not sure why you are using `getSettings` to begin with. It will return an array of your properties, so it's the same as `this->regionType` (just a little bit slower). Twig doesn't separate between  array or object syntax, it's the same but in PHP you have a different syntax between arrays and objects  
> **username_0**: I think I'm not understanding how to access pre-stored settings for a field. In response to your original answer I just added `public $regionType` to my field class. But how do I grab the stored settings so I can use them to set which options display in the field? If I just use `$this->regionType` then all I get is a null value. I thought `$this->getSettings()` was the way to pull in the stored settings?  
> **username_1**: What are pre-stored settings? Each field has settings that represents certain attributes of the class. When you save a field Craft will serialize your body params and store them as settings in your fields table. When you populate it the next time Yii2 will configure your field class with those attributes that are stored as JSON in your fields table  
> **username_0**: Ah, OK I see now. I thought I had to explicitly go and grab the settings properties but they're already pre-loaded for me.  

---

