Skip to main content

Sitecore Web Forms for Marketers (WFM) styling and lessons learned

I recently spent some time trying to use Web Forms for Marketers doing some custom styling and custom save action. I learned a few things along the way and wanted to share. I learned there are some times to use Web Forms for Marketers and some times not to use it. The goal of this article is to explain those consideration and help others learn some tips to understand why it may or may not be a fit. The module has some cool features and in some regards can be pretty slick. However, in other ways it can be a pain to use and provide no flexibility in some areas. This article is based on Web Forms for Marketers version 2.3.

Styling

The module sells itself as a control that can be styled anyway you want it. Well, that is kind of true. There are two ways you have control over the styling of Web Forms for Marketers, via the style sheets and via the Sitecore based module admin UI.

Module’s Sitecore admin UI

The Sitecore based admin UI comes with the module so lets start there. This UI does provide a way to assign styles to an input field via the “Css Class” field. Here you can assign a custom class to style the input box. You need to create a imagenew CSS class in the module settings (all this is documented in the guide). If that is all you want (to tally style the textbox) you are good to go. All text boxes have the same style applied to them. Internally what happens is the information in your assigned CSS style is indirectly applied to the text box, dropdown box or checkbox. So some fidelity of control is lost.

Here are a few gotchas with this type of styling no one mentions. 1) You have no control over the field’s label style via this interface. 2) You have no control over the fields validation styling via this interface and 3) Even though you can tell it rather or not to show a title and footer if you say no to either or both the control still reserves space for those areas. So if you don’t want headers and footers you still have to deal with extra space above and below the form for them.

 

So if you want authors to control creation of forms and their styling, the styling requirements need to be pretty basic and stay similar to the default styling. If you have unique styling needs for forms on the site which go beyond text box styling and setting a required filed asterisk, this module is probably not a good fit. 

Here is the form I was trying to do.

image

As you can see it’s style is very different from what the default form spits out. I needed to hide my labels, have default text in the textbox and have special validation styling.

The default validation styling puts an error message to the right of the text box (by the way, you cannot control the error labels color. Even if you update the stylesheet the color is hardcode in their code behind). Validation also has a validation summary as a bulleted list below the form title. Again you have no control, via the UI, over rather or not this is shown or how it is shown (list, bulleted, paragraph, etc). For me I just wanted a red “required” text to show up top and the textbox to be outlined in red (more on this later).

 

Module’s Style Sheet

To style some of these more “advanced” things you need to venture into the Default.css that drives the form style. It was easy enough to hide all the labels this way. Just find the correct css style and update it to “display: none;” This is great if all your forms on the site will not have labels because when you change things in the style sheet it applies to all WFM forms added to the site. So if a content author wants a form on one page with labels they are out of luck. You can also turn off some of the validation styles here like the “*” next to required fields.

There are two default.css style sheets, one in themes and one in the module root. There is also a custom.css that you can add styles to. You do have a lot of control via these styling sheets, but it is key to remember the changes  you make here are global to the site and cannot be controlled via the admin UI. This means content authors have no control.

Save actions

One of the great things about this module is all the save actions you can attached to the submit button. You can save to the Sitecore database, send emails, create user accounts and lots more. You can even create custom actions. I will write another post on creating a custom save action. This is more focused on the implications of needing to do this. First, finding details on how to do this and what objects you can wire into is pretty limited. Second, if there is any configuration needed for your save action  you have to create a sheer UI for all of this (also not a lot of documentation on this either). The ability to wire into all these different events and Sitecore items can be powerful though.  You can do pretty much anything you need to via a custom save action. If you need to use some of the included Sitecore based action plus a custom save action this module maybe a good fit. If you only need your own custom action it may not be a good fit, unless some of the other areas are a good fit.

Validation

To be honest, I am pretty disappointed by the level of control over validation this module provides. In some respects it provides some great things, for other areas it levels the author and/or developer out in the cold. As you can see from the above screenshot, the module lets you specify if a field should have a validator for required filed, or for how many characters the field can have. You can also apply some regular expression, even a custom regular expression. You also get a validation summary and validation messages next to each field (you can control only some of the validation text that is displayed). Again if this is all you want it may be a good fit.

Some of the areas where validation can trip you up. If you don’t want each field to show its validation error but only want the summary control to show the message. The only way you can control this is by updating the css file to style those field so they are not visible, again this means it is turned off for all forms. Same is true for the validation summary control. If you want custom text to show for the validation summary control you are out of luck as well. You also cannot set the default value of a field and in turn set the initial value of the required field validator (this allows for a form like above where the label is actually the initial text of the field. Settings these values lets the required validator mark the field as invalid if a new value is not provided). You can export the form to a user control (ascx file) but this kills your non-IT based authoring story, which is one of the bigger reasons to use this module anyway. You also cannot apply custom error styling. For me I wanted to mark the field with a red boarder if validation failed, again you can do this in the code behind if you export to a user control, but now  you are really starting to swim upstream.

Summary

In short here are some of the things I would look at to decided if Web Form for Marketers is a fit.

I would lean away from WFM if:

  • No need for Sitecore based form actions
  • No need for content authors to manage and create forms on their own
  • Custom styling, outside of input items (textbox, dropdown list, etc) is needed
  • You want your field labels to be the initial value of the field
  • You need some custom validation summary and error message styling

I would lean toward WFM if:

  • Your styling needs are pretty basic or styling is global enough and limited enough so as to apply to all forms
  • You need the included Sitecore integrated actions
  • Module analytics are needed to track form submissions and other stats
  • Non-IT resourced or pure content authors must have ability to author forms and control them

Hopefully this helps you understand the pros and cons of this module and how you can position it. If you need to use WFM just be aware of the pitfalls and try to work around them during requirements and design. I am sure there are other options as well, and if you have them please let me know.

Comments

Anonymous said…
Hello there! This is my first visit to your blog! We are a group of volunteers and starting a new initiative
in a community in the same niche. Your blog provided us useful information to
work on. You have done a outstanding job!

Also visit my homepage; Title Search Education -
-

Popular posts from this blog

MVVM light and Model Validation

I have been using the MVVM light toolkit for a project recently. It is a great toolkit but is missing a couple things and Laurent Bugnion does a good job trying to cover those holes. One of the things the toolkit does not support is Validation. The good news is there is a great CodePlex project out there call Fluent Validation that makes this pretty easy to add and really powerful. My objective was to add validation to my model so I could call “IsValid” on the model itself (similar to the MVC attribute approach). Fluent Validation has you create a new class file that holds you validation rules for a given model. This is the approach I took to enable each model to have an “IsValid” property and a “Errors” property that returns the validation errors.First I setup my ValidationFactory:publicclass ValidatorFactory : FluentValidation.ValidatorFactoryBase{publicoverride FluentValidation.IValidator CreateInstance(Type validatorType) {return SimpleIoc.Default.GetInstance(validatorType) as …

Experience Profile Anonymous, Unknown and Known contacts

When you first get started with Sitecore's experience profile the reporting for contacts can cause a little confusion. There are 3 terms that are thrown around, 1) Anonymous 2) Unknown 3) Known. When you read the docs they can bleed into each other a little.

First, have a read through the Sitecore tracking documentation to get a feel for what Sitecore is trying to do.

There are a couple key things here to first understand:

Unless you call "IdentifyAs()" for request the contact is always anonymous. Tracking of anonymous contacts is off by default. Even if you call "IdentifyAs()" if you don't set facet values for the contact (like first name and email) the contact will still show up in your experience profile as "unknown" (because it has no facet data to display).  Enabled Anonymous contacts


Notice in the picture I have two contacts marked in a red box. Those are my "known" contacts that I called "IdentifyAs" on. I know they say &…

Excel XIRR and C#

I have spend that last couple days trying to figure out how to run and Excel XIRR function in a C# application. This process has been more painful that I thought it would have been when started. To save others (or myself the pain in the future if I have to do it again) I thought I would right a post about this (as post about XIRR in C# have been hard to come by). Lets start with the easy part first. In order to make this call you need to use the Microsoft.Office.Interop.Excel dll. When you use this dll take note of what version of the dll you are using. If you are using a version less then 12 (at the time of this writing 12 was the highest version) you will not have an XIRR function call. This does not mean you cannot still do XIRR though. As of version 12 (a.k.a Office 2007) the XIRR function is a built in function to Excel. Prior version need an add-in to use this function. Even if you have version 12 of the interop though it does not mean you will be able to use the function. The a…

WPF Localization - RESX Option

About a year ago I was building a WPF project in .Net 3.0 and Visual Studio 2005. I wanted to revisit this subject and see what has changed in .Net 3.5 and Visual Studio 2008. I will make a few of these posts to try and cover all the different options (RESX option, LocBaml option, Resource Dictionary Option). In this blog I will focus on using a resx file to localize an application. To show how the resx option is done I created a WPF form with three labels on it. The first label has is text set inline in XAML, the second has it text set via code behind from the resx file and the third has its text set via XAML accessing the resx file. The first thing that needs to happen to setup a project for localization is a small change to the project file. To make this change you will need to open the project file in notepad (or some other generic editor). In the first PropertyGroup section you need to add the follow XML node <UICulture>en-US</UICulture>. So the project file node woul…

Uniting Testing Expression Predicate with Moq

I recently was setting up a repository in a project with an interface on all repositories that took a predicate. As part of this I needed to mock out this call so I could unit test my code. The vast majority of samples out there for mocking an expression predicate just is It.IsAny<> which is not very helpful as it does not test anything other then verify it got a predicate. What if you actually want to test that you got a certain predicate though? It is actually pretty easy to do but not very straight forward.Here is what you do for the It.IsAny<> approach in case someone is looking for that. this.bindingRepository.Setup(c => c.Get(It.IsAny<Expression<Func<UserBinding, bool>>>())) .Returns(new List<UserBinding>() { defaultBinding }.AsQueryable()); This example just says to always return a collection of UserBindings that contain “defaultBinding” (which is an object I setup previously). Here is what it looks like when you want to pass in an expressi…