Jump to:

1999 Posts in 1421 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » Why is field layout hard-wired in FormField.php and not in a template?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1213 Views
  • losqualo
    Avatar
    Community Member
    17 Posts

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

    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.

    Rob

  • Willr
    Avatar
    Forum Moderator
    5483 Posts

    Re: Why is field layout hard-wired in FormField.php and not in a template? Link to this post

    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!

  • losqualo
    Avatar
    Community Member
    17 Posts

    Re: Why is field layout hard-wired in FormField.php and not in a template? Link to this post

    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.

    Rob

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: Why is field layout hard-wired in FormField.php and not in a template? Link to this post

    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 FormTransformation is there an easier way I am missing here?

    1213 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.