I am rendering a Zf2 form which contains a fieldset as a child element (simplified for this ticket):
class RegistrationForm extends Form
{
public function __construct($name = "company_registration_form", array $options = [])
{
parent::__construct($name, $options);
$user = new UserFieldset('user');
$this->add($user);
$this->setValidationGroup([
'user' => [
'nameFirst',
],
]);
}
}
The fieldset is defined as following:
class UserFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct($name = 'user', $options = [])
{
parent::__construct($name, $options);
$this->add([
'name' => 'nameFirst',
'type' => 'Zend\Form\Element\Text',
'required' => false,
'options' => [
'label' => _('Vorname'),
'label_attributes' => [
'class' => 'left inline'
],
],
'attributes' => [
'class' => 'left',
],
]);
}
And at last the twig template used for rendering the form:
{{ form().prepare() }}
{{ form().openTag(form)|raw }}
{{ formLabel(form.get('user').get('nameFirst'))|raw }}
{{ formInput(form.get('user').get('nameFirst')) }}
{{ form().closeTag(form)|raw }}
The HTML output looks like this:
<form id="company_registration_form" data-abide="" name="company_registration_form" method="post" novalidate="novalidate">
<label for="nameFirst" class="left inline">Vorname</label>
<input type="text" value="" class="left" name="nameFirst" aria-invalid="false">
</form>
As you can see, the name parameter is not correctly set. It should be name="user[nameFirst]", instead of the plain field name. When i render the same form with .phtml (no changes made to forms) the name value is set correctly.
Therefore, i assume that the view helper handles the fieldset differently in case of twig templates. Could you please give me any directions how to fix this issue? Is this a bug or am I rendering the template incorrectly.
Many thanks for the answers.
Our composer.json looks like this:
{
"require": {
"zendframework/zendframework": "2.5.1",
"doctrine/doctrine-orm-module": "0.9.1",
"zf-commons/zfc-twig": "1.2.2",
"zf-commons/zfc-user": "1.2.2",
"zf-commons/zfc-user-doctrine-orm": "1.0.1",
"bjyoungblood/bjy-authorize": "1.4.0",
"gedmo/doctrine-extensions": "v2.4.4",
"twig/extensions": "v1.2.0"
}
}
I am rendering a Zf2 form which contains a fieldset as a child element (simplified for this ticket):
The fieldset is defined as following:
And at last the twig template used for rendering the form:
{{ form().prepare() }} {{ form().openTag(form)|raw }} {{ formLabel(form.get('user').get('nameFirst'))|raw }} {{ formInput(form.get('user').get('nameFirst')) }} {{ form().closeTag(form)|raw }}The HTML output looks like this:
As you can see, the name parameter is not correctly set. It should be name="user[nameFirst]", instead of the plain field name. When i render the same form with .phtml (no changes made to forms) the name value is set correctly.
Therefore, i assume that the view helper handles the fieldset differently in case of twig templates. Could you please give me any directions how to fix this issue? Is this a bug or am I rendering the template incorrectly.
Many thanks for the answers.
Our composer.json looks like this: