Jump to:

10843 Posts in 2514 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » UserForms EditableHiddenField (customized)

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 871 Views
  • Xurk
    Avatar
    Community Member
    50 Posts

    UserForms EditableHiddenField (customized) Link to this post

    While working on a site this morning, I noticed that there was no "HiddenField" option in the current version of UserForms. I wanted to add one to the form with a default value* and use that field to decide where the e-mail should be sent to after submission. Depending on a selection the user makes within the form, the default value of the HiddenField should be altered.

    Seeing as there was no HiddenField, I set out to add it to the myself and thought I'd share the results with everyone in case someone else wants to add the functionality but doesn't have the time to sort it out themselves I've attached a ZIP archive to this post which holds all the necessary files (one optional file, which I'll get to in a minute) in the designated directories. Just copy them into the UserForms directory and run a "dev/build" and flush the website. Then you should be good to go! I also added a little icon which is used next to the field when you add it.

    It's really a quite simple customization, nothing very fancy going on. One thing I wanted to add but couldn't figure out, is how to get rid of the "CustomRules" fieldset group within the "Options" part of the field. I managed to get rid of the "Validation" fieldset group, but the CustomRules one seems more persistent ;)

    The optional file is the core "UserDefinedForm.php". You don't need it to enable HiddenFields in UserForms, but I've edited it so that HiddenFields are included in the "Select a Field to use as the To Address" DropdownField on the "Email Recipients" tab, which I needed for my solution to work.

    If there are any questions or suggestions on this customization, just let me know!

    * I noticed that the "EditableFormField" database table does have a column named "Default" which I presume is for default FormField values, but I couldn't seem to find any way to set it (not even with $this->Default, following the style of similar columns referenced in the code). So I ended up with storing the default value for a HiddenField in the CustomSettings field. That said, is there any possibility of the "Default" column being utilized in future versions of UserForms, or would I need to look into that myself?

    Attached Files
  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: UserForms EditableHiddenField (customized) Link to this post

    Just copy them into the UserForms directory and run a "dev/build" and flush the website. Then you should be good to go! I also added a little icon which is used next to the field when you add it.

    You shouldn't need to copy anything into the userforms directory. It'll make upgrading later on harder. UserForms will pick up form fields and templates from your theme and modules as well automagically.

    The optional file is the core "UserDefinedForm.php". You don't need it to enable HiddenFields in UserForms, but I've edited it so that HiddenFields are included in the "Select a Field to use as the To Address" DropdownField on the "Email Recipients" tab, which I needed for my solution to work.

    If you're hardcoding the to address in the form, any reason why you couldn't just hardcode that address as the To field in the email recipient tab.

    871 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.