I stumbled across something odd today.
When i create a field in a modal-form and the name of the form-field matches the field-name then the field value gets overridden by the submitted value.
Is this behaviour intended?
Here is a test field.
Hope it is somehow understandable ![]()
Edit:
Did some further testing.
The unexpected behaviour occurs when you specify a field in a blueprint where the field-name matches the name attribute from the form input.
The blueprint test.yml
title: Test
fields:
title:
label: Title
type: title
test:
label: Test
type: test
And in the field form test/form/action.php
$form = new Kirby\Panel\Form(array(
'test' => array(
'label' => 'Label',
'type' => 'checkboxes',
'options' => $options,
'icon' => 'chevron-down',
)
));
When I try to acces the the field value in the action controller I get the submitted form values.
test/controller.php
public function action() {
dump($this->field()->value());
$self = $this;
$parent = $this->model()->page();
if($parent->ui()->create() === false) {
throw new PermissionsException();
}
$form = $this->form('action', array($parent, $this->model()), function($form) use($parent, $self) {
try {
$form->validate();
if(!$form->isValid()) {
throw new Exception(l('pages.add.error.template'));
}
} catch(Exception $e) {
$self->alert($e->getMessage());
}
});
return $this->modal('action', compact('form'));
}
When I change the field name in the blueprint from test to lorem for example everything works as expected.
title: Test
fields:
title:
label: Title
type: title
lorem:
label: Test
type: test
Cheers
Lukas
