Search code examples
phpformszend-framework2zend-formprefix

Zend Framework 2 - Set prefix for form elements


I'm looking for a way to add prefixes for every element of a certain form.

If found this post telling me that there is a elementsBelongTo option which I can use to achieve what I want.

Unfortunately I can't find any documentation explaining the usage. Does anyone know how I can use this option? And if it's still in ZF2?

And furthermore: I there a way to combine it with the nice AnnotationForms?


Solution

  • Don't know if it will help, but instead of prefix you can wrap elements in form or fieldset with form/fieldset name.

    You just need to have a name of form or set it and then use setWrapElements

    $form->setName('some_name');
    $form->setWrapElements(true);
    $form->prepare();
    

    from this point full name of element, for example 'password' will be "some_name['password']"

    If you are using annotations you can use this with combination of ComposedObject. It's very good explained here: http://devblog.x2k.co.uk/using-the-composedobject-zend-framework-2-form-annotation/