I was looking at someone’s support web page and they had the same form multiple times on that page. It was “Did you find this information helpful?” forms.
The support page had different sections of different types of help. Each section was a MODX chunk. Inside each chunk was a formit snippet. Each formit needed some uniqueness added to it, like the Formit submitVar & successMessagePlaceholder. The form code also had some elements that needed to be unique as well.
Since each section was a chunk with almost identical formit snippet calls and form code, I had originally thought to see if MODX chunks had short tags that could identify itself. Then I could give the formit snippets and form code some uniqueness. My thoughts were to do something like this with formit snippet call and place [[+chunkname]] where needed, since MODX Chunk names are unique:
[[!FormIt?
&hooks=`FormItSaveForm,spam`
&formName=`Page: [[*alias]]`
&store=`1`
&validate=`nospam:blank`
&submitVar=`submit_ynform[[+chunkname]]`
&successMessage=`[[$tpl_support_successMessage]]`
&successMessagePlaceholder=`successMessagePlaceholder[[+chunkname]]`
&formFields=`helpful,section,url`
]]
I grew past that thought after realizing that the “Did you find this information helpful?” forms are going to be added to other pages multiple times. So, I settled upon writing a snippet called support_formit
because the Formit snippet call, form code, design, and functionality were going to be the same for each form. Calling one snippet that is going to do the exact same thing multiple locations throughout the website seemed to leave less room for error and design inconsistency.
The new snippet call is simply:
[[!support_formit? &form_section=support_topic_1
]]
Where the form_section
value can be whatever you want when applying it to the help sections. The form_section
just needs to be unique so that the functionality works specific to the section of the web page where the form is submitted.
Then you can see an example of how I use the snippet and the value of form_section
when making a formit snippet call:
[[!FormIt?
&hooks=`FormItSaveForm,spam`
&formName=`Page: [[*alias]]`
&store=`1`
&validate=`nospam:blank`
&submitVar=`submit_ynform<?php echo $form_section; ?>`
&successMessage=`[[$tpl_support_successMessage]]`
&successMessagePlaceholder=`successMessagePlaceholder<?php echo $form_section; ?>`
&formFields=`helpful,section,url`
]]
I am sure that I could think of other ways why having short tags, like [[+chunkname]], [[+chunkid]], etc., for chunks and snippets would be useful. But my original thought is detailed above why I thought it would be useful at the time.