i’m using Uniform to display a contact form on my contact page. For now this contact form is placed inside the template »contact.php« since there is a controller from uniform that requires it to be inside a template.
Since i’m using modules where every subpage is display as a snippet, i want the same thing for that contact form. But if i do so the code gets broken – i think because of the missing controller. Is it possible to achieve something like this? That would be of very great help. Any suggestions?
If you really want to use the form as a snippet in multiple templates there is nothing holding you back from moving the Uniform controller code right into that snippet. It’s not as elegant as one controller for one template but arguably better than duplicating the Uniform controller code for each template using the snippet.
Just make sure situations with multiple occurrences of the form snippet on the same page are handled correctly (each form needs a unique ID).
O.K. Thanks for that. texnixes advices worked for me. I tried all the other versions but not the simplest one… Could you give me a short advice on what to do to get more fields work? Such as Street, City, Phone etc.? That would be of great help.
Check out the example section of the readme. The extended example has lots of different fields.
It’s basically only the HTML of a form field with the $form->echoValue() somewhere for each field so the content is not lost if an error occurs.
If you want a mandatory field or do validation you have to add the field name to the required or validate arrays respecively and add the $form->hasError() stuff to the field so it can have a proper error state via CSS.