I’m working on a Sitecore implementation where there are many forms throughout the site (before you ask, WFFM is out of the question!).
My question is, what is the best way to store the form labels? My current thinking is to use a dictionary structure and access form field labels by key. The problem with this approach is when editors want to vary the label for the same field; e.g. on form X the first name field is “First Name” then perhaps somewhere else it could be “Forename” or maybe it’s a required field (with asterisk) in one place an optional in another. I don’t really want to start having dictionary items called “FirstNameWithAsterisk” and “FirstNameWithoutAsterisk” etc.
One other thought I’ve had is to simply store the form labels in a Name Value List field. This field could then be populated with Names/Values like and editors would be free to use whatever form labels they like, without risk of inadvertently editing a dictionary entry used somewhere else.
I’ve been down the route before of having form fields on the page template, but this is a pretty horrible solution IMHO so I wouldn’t be interested in going down this route again.
EDIT
To confirm, there are a finite number of forms for this site.
I would go with the dictionary approach. If your argument is that it could vary, then that’s a reason to logically separate them. So, it sounds like you have custom forms and a finite set of forms to be built (please confirm). That said, build your dictionary just like that, e.g.
Or another naming convention that makes sense for you.
Logically its the “first name field” for each unique form, but they’re technically two separate unrelated things, hence you would want two dictionary items for them. You could do this via a naming convention that you alluded to, but don’t name them based on the content, (since that value changes!), instead name it based on what it applies to / where it’s used since your code will statically refer to the key.
So I would say
FirstNameWithAsteriskandFirstNameWithoutAsteriskare bad names because they tie to the content and whether it has or doesn’t have an asterisk. Instead, name it by the form it applies to or some other general notion of the content.Edit: Since the same form component can be added to more than one page then this is a perfect case for a data source of that presentation component. Simply create a template for all of the form fields, then create any number of instances of those and for each form bound to a page, point its data source to the respective item with the desired field values.