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
name
attributes don't quite match yourSettings
model properties. I seeagegateDeclineButton
in the template, butagreeButtonLabel
in the model; it does seem like the correct properties are being set back on the input for theirvalue
attributes, though! (i.e.settings.agreeButtonLabel
)