Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » SilverStripe documentation badly needs a complex and complete form example!

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

Page: 1
Go to End
Author Topic: 2429 Views
  • Codetapper
    Avatar
    Community Member
    8 Posts

    SilverStripe documentation badly needs a complex and complete form example! Link to this post

    I've read a lot of posts in the form section, and the same sorts of questions keep coming up. I think a complete form tutorial that does more than just "this field requires some text" would really solve a lot of problems and eliminate a lot of forum questions!

    Please note: I would happily write one if I knew how to get the form working as I want!

    I think most users would appreciate a tutorial that does the following:

    Sets up a form
    Styles it (an asterisk beside required fields), perhaps lay it out in columns rather than the name with the field underneath it.
    Allows you to change the "Sorry this field is required" type message for each field (if that's possible)
    Optional parts that if a field is set to a certain value, it brings up another section.
    A radio button list that has "Other" at the bottom, and if the radio button is set to that, a text field with "Other" appears (or is enabled, or whatever) allowing you to type in the text.
    Checkbox behaviour similar to the above radio buttons

    I think it REALLY needs to have client and server validation options too:
    If a particular value is set in a field, a message appears.
    If the user submits the form and parts are invalid, the server can return the form again with "this bit is invalid" on a certain field.

    Has anyone managed to do anything like the above? I would love to see any code dealing with forms in this manner. In ASP/PHP on my own forms, I can do all sorts of stuff and I was hoping it would be just as easy in Silverstripe, but I get stuck and limited to validation along the lines of "this field must have a value in" and that's about it!

    Some developer or SS legend - please help us!

    PS: I have tried the UserDefinedForm which seems to have some great promise, but it doesn't work properly in Silverstripe (2.3.1 and I tried with 2.3.3 aswell) - loads of errors appear and I got fed up with it!

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: SilverStripe documentation badly needs a complex and complete form example! Link to this post

    I think this is more a case of revising the validation API (both PHP and JS) in SilverStripe, making it more pluggable and configurable. We know about these problems, but currently can't devote significant time to it. See our (slightly outdated) initial brainstorms at http://open.silverstripe.com/wiki/development/validation. We're looking for external developers who can significantly contribute here, so anybody taking the charge here is welcome.

    > Styles it (an asterisk beside required fields), perhaps lay it out in columns rather than the name with the field underneath it.

    We usually add simple HTML markup:
    new TextField('MyText', 'MyText <span class="required">*</span>')
    You can automate this a little bit further by iterating through all fields and append this only to required ones:
    foreach($myForm->Fields() as $field) {
    if($field->Required()) $field->setTitle($field->Title() + <span class="required">*</span>');
    }

    > Allows you to change the "Sorry this field is required" type message for each field (if that's possible)

    Currently this is difficult due to Validator.js javascript implementation. I recommend disabling built-in javascript validation,
    and using a more fully featured library like jquery.validate.

    > Optional parts that if a field is set to a certain value, it brings up another section.
    A radio button list that has "Other" at the bottom, and if the radio button is set to that, a text field with "Other" appears (or is enabled, or whatever) allowing you to type in the text.

    Both pretty custom features (dependent dropdowns etc.), seems like a case for custom javascript or a small jQuery plugin, rather than FormField PHP core.

  • Codetapper
    Avatar
    Community Member
    8 Posts

    Re: SilverStripe documentation badly needs a complex and complete form example! Link to this post

    Thanks for those suggestions!

    How exactly do you disable the javascript validation and use jquery instead? This is where a working example doing some of those things would be so useful - and probably a lot easier than changing the sapphire core!

  • Ingo
    Avatar
    Forum Moderator
    801 Posts
    2429 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.