Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions

Why is field layout hard-wired in FormField.php and not in a template?


4 Posts   1250 Views


6 September 2010 at 2:00pm (Last edited: 6 September 2010 2:01pm), Community Member, 17 Posts

I've been wondering where the nested div structure surrounding form fields came from since I could find no template anywhere that specified this.

I finally found it within the FormField.php file (sapphire/forms/FormField.php), which seems a little odd... The functions 'Field', 'FieldHolder' and 'SmallFieldHolder' are all culprits in actually generating html, instead of passing data to a template.

Is there any particular reason for doing it this way? It makes customising form structure more complicated than just having a suitable template local to the site folder.

So, to get around this and regain control, what is the best route. Do I create a local copy of FormField.php as mysite/code/CustomFormField.php?

That being the case, should it extend FormField or RequestHandler, or would either one do?

Also, how and where do I control the insertion of javascript related to form fields that don't exist? For example, my search form consists of an input and an action, yet there is javascript being auto inserted that relates to select lists and textareas that aren't there... Why? Can they be safely removed and if so, how/where?

Thanks in advance.



6 September 2010 at 6:50pm Forum Moderator, 5511 Posts

The reason for this is because in the CMS it was including over 100 form fields per request so having them as templates slowed the CMS down significantly. The change happened over 3 years ago so with the new Zend Caching for the templates might render this point as moot but at the time the performance improvement was worth the hassle!


6 September 2010 at 7:42pm Community Member, 17 Posts

Thanks Will,

If I want to apply different layout/markup on specific forms then what would be the best way of achieving this?

Is it possible to have a mysite/code/customFormField.php for this...

I'm having problems with the middleColumn div and form verification (via javascript)

Ideally I'd want the middleColumn background colour to change on error, as well as displaying any error message. The classes however change on the input field within the middleColumn div.

I either have to change the javascript to apply the 'error' class to the containing div or the middleColumn div, or change background colour on middleColumn directly. Changing the outer class would be the preferred way to go allowing styling to be setup through the stylesheet.

In either case I've not yet found where the javascript gets setup to get a handle on what or where to make changes.

I'm looking forward to the day in a few months time when all this will seem trivially easy to me... right now it's overwhelming.



23 January 2012 at 4:05pm (Last edited: 23 January 2012 4:06pm), Community Member, 105 Posts

I would also like to know this have tried to subclass FormField and overload the FieldHolder so I can render the form fields with custom markup.

I created a class CustomFormField extends FormField added it it to config but get error:

Fatal error: Object::add_extension() - Extension "CustomFormField" is not a subclass of Extension

Was looking at [url=]FormTransformation[/url] is there an easier way I am missing here?