I have a Symfony2 form where a user can enter an address that is now in a fixed format, and since we want to offer our software internationally, I'm looking for the best way to implement this in SF.
Instead of creating one common, address typewe would like to localize forms with one common format as a reserve for unsupported locales.
I want to separate layout and localization (order, grouping, labels, translations, required and optional fields) from processing (PHP / SF) forms and actual rendering (TWIG).
I came to this: create a form type addressfrom a database model containing all possible fields. Add this form type to the branch automatically by calling form_widget(form)or, if necessary, individual fields. And finally; Define the "layout" of the form in some configuration format (YML, array, whatever) and extend the default TWIG form rendering to iterate through the form elements defined in the specified configuration.
For example, the address configuration for the Netherlands and the USA will be:
- NL-nl
- [firstname, infix, lastname]
- [street1, number]
- [postcode, city]
- EN-us
- [fullname]
- [street1]
- [street2]
- [city, state]
- [zip]
Later we will add localized labels, classes, optional and required fields, etc. to this configuration.
At the moment, our big question is: where to put this config? Use a simple array in a class finishView? Put the configuration in a YML file that is processed by form types that require a localized form layout?
, .