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.

All other Modules /

Discuss all other Modules here.

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

UserForms EditableHiddenField (customized)


Reply


2 Posts   1023 Views

Avatar
Xurk

Community Member, 50 Posts

2 June 2011 at 12:21am

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
Avatar
Willr

Forum Moderator, 5513 Posts

2 June 2011 at 7:06pm

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.