Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZF2 Fieldset rendering: name parameter is not set correctly in forms #109

Open
catilgan opened this issue Aug 11, 2015 · 1 comment
Open

Comments

@catilgan
Copy link

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"
    }
}
@Alfredao
Copy link

Alfredao commented May 5, 2018

Had you find a solution? I have the same problem here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants