<p>Craft automatically sets values from the incoming POST data on your <code>Settings</code> model, which means the input <code>name</code> attributes must match <em>exactly</em> (or that the <code>Settings</code> model must expose an appropriate “setter” method).</p>
<p>It appears that your class property is <code>agreeButtonLabel</code> (not <code>agegateAgreeButton</code>), which means that its field’s macro call should look like this:</p>
<pre><code>{{ forms.textField({
    label: 'Agree Button',
    name: 'agreeButtonLabel',
    value: settings.agreeButtonLabel,
}) }}
</code></pre>
<p>I suspect this was ultimately just a typo, because you already had the correct property name for the <code>value</code> part of the macro!</p>

CC BY-SA 4.0
2023-03-12T19:05:35.633Z
2023-03-12T19:05:35.633Z
August Miller
<p>After following the &quot;How to build a plugin&quot; from the official CraftCMS docs, I've started extending the Control Panel Template from 1 to multiple fields, all are of the same type string and all &quot;fields&quot; use a simple Textfield</p>
<p>Here the Model:</p>
<pre><code>class Settings extends Model {
    public $pluginName = 'AgeGate';
    public $isAgeGateEnabled = true;
    public $minimumAgeAllowed = 10;
    public $agegateTitle = 'Age Verification';
    public $agegateContent = 'Verify your age';
    public $dayPlaceHolder = 'DD';
    public $monthPlaceHolder = 'MM';
    public $yearPlaceHolder = 'YYYY';

    public $agreeButtonLabel = 'Enter';
    public $declineButtonLabel = 'Leave';
    public $failureMessage = 'You are not old enough to enter this site';


    public function defineRules(): array {
        return [
        ];
    }
}
</code></pre>
<p>and here the settings template</p>
<pre><code>{% import '_includes/forms.twig' as forms %}

{{ forms.textField({
    first: true,
    label: 'Minimum Age Allowed',
    name: 'minimumAgeAllowed',
    value: settings.minimumAgeAllowed
}) }}

{{ forms.textField({
    label: 'Title of Age Gate',
    name: 'agegateTitle',
    value: settings.agegateTitle
}) }}

{{ forms.textField({
    label: 'Content of agegate',
    name: 'agegateContent',
    value: settings.agegateContent
}) }}

{{ forms.textField({
    label: 'Agree Button',
    name: 'agegateAgreeButton',
    value: settings.agreeButtonLabel
}) }}

{{ forms.textField({
    label: 'Decline Button',
    name: 'agegateDeclineButton',
    value: settings.declineButtonLabel
}) }}
</code></pre>
<p>I don't have any problems saving the first three fields, but when changing the content of the last 2 fields my changes don't get updated.</p>
<p>I just can't see the reason why certain fields get updated and others not. Did anyone had this issue before?</p>
<p>Note: defineRules is empty on purpose for testing as currently i don't care about validating input</p>

CC BY-SA 4.0
2023-02-23T19:31:46.567Z
It looks like your input `name` attributes don't quite match your `Settings` model properties. I see `agegateDeclineButton` in the template, but `agreeButtonLabel` in the model; it _does_ seem like the correct properties are being set back on the input for their `value` attributes, though! (i.e. `settings.agreeButtonLabel`)
August Miller
CC BY-SA 4.0
2023-02-23T19:50:45.067Z
I see I see.. so the name and value need to be the same.
funkysoul
CC BY-SA 4.0
2023-03-02T22:06:48.740Z
@funkysoul if that ends up fixing it for you, let us know so August can add it as an official answer!
Brad Bell
CC BY-SA 4.0
2023-03-03T13:24:55.653Z
Hi Brad, yes definitely, Augusts comment was the right answer.
funkysoul
CC BY-SA 4.0
2023-03-03T16:20:29.373Z
@AugustMiller you're up!
Brad Bell
CC BY-SA 4.0
2023-03-12T19:06:26.640Z
Added! Thanks for the ping. 
August Miller
<plugin-development><craft4><custom>
Craft 4 Building a Plugin not saving all properties
# Craft 4 Building a Plugin not saving all properties

(Asked by: username_0 on 2023-02-23)

After following the "How to build a plugin" from the official CraftCMS docs, I've started extending the Control Panel Template from 1 to multiple fields, all are of the same type string and all "fields" use a simple Textfield
Here the Model:
class Settings extends Model {
    public $pluginName = 'AgeGate';
    public $isAgeGateEnabled = true;
    public $minimumAgeAllowed = 10;
    public $agegateTitle = 'Age Verification';
    public $agegateContent = 'Verify your age';
    public $dayPlaceHolder = 'DD';
    public $monthPlaceHolder = 'MM';
    public $yearPlaceHolder = 'YYYY';

    public $agreeButtonLabel = 'Enter';
    public $declineButtonLabel = 'Leave';
    public $failureMessage = 'You are not old enough to enter this site';


    public function defineRules(): array {
        return [
        ];
    }
}

and here the settings template
{% import '_includes/forms.twig' as forms %}

{{ forms.textField({
    first: true,
    label: 'Minimum Age Allowed',
    name: 'minimumAgeAllowed',
    value: settings.minimumAgeAllowed
}) }}

{{ forms.textField({
    label: 'Title of Age Gate',
    name: 'agegateTitle',
    value: settings.agegateTitle
}) }}

{{ forms.textField({
    label: 'Content of agegate',
    name: 'agegateContent',
    value: settings.agegateContent
}) }}

{{ forms.textField({
    label: 'Agree Button',
    name: 'agegateAgreeButton',
    value: settings.agreeButtonLabel
}) }}

{{ forms.textField({
    label: 'Decline Button',
    name: 'agegateDeclineButton',
    value: settings.declineButtonLabel
}) }}

I don't have any problems saving the first three fields, but when changing the content of the last 2 fields my changes don't get updated.
I just can't see the reason why certain fields get updated and others not. Did anyone had this issue before?
Note: defineRules is empty on purpose for testing as currently i don't care about validating input

**Tags:** plugin-development, craft4, custom
> **Comments:**
> **username_1**: It looks like your input `name` attributes don't quite match your `Settings` model properties. I see `agegateDeclineButton` in the template, but `agreeButtonLabel` in the model; it _does_ seem like the correct properties are being set back on the input for their `value` attributes, though! (i.e. `settings.agreeButtonLabel`)  
> **username_0**: I see I see.. so the name and value need to be the same.  
> **username_2**: @funkysoul if that ends up fixing it for you, let us know so August can add it as an official answer!  
> **username_0**: Hi Brad, yes definitely, Augusts comment was the right answer.  
> **username_2**: @AugustMiller you're up!  
> **username_1**: Added! Thanks for the ping.   

---

## 1 answers

### Answer by username_1 on 2023-03-12. Score: 3 | Accepted answer

Craft automatically sets values from the incoming POST data on your Settings model, which means the input name attributes must match exactly (or that the Settings model must expose an appropriate “setter” method).
It appears that your class property is agreeButtonLabel (not agegateAgreeButton), which means that its field’s macro call should look like this:
{{ forms.textField({
    label: 'Agree Button',
    name: 'agreeButtonLabel',
    value: settings.agreeButtonLabel,
}) }}

I suspect this was ultimately just a typo, because you already had the correct property name for the value part of the macro!


---

