Error When Rendering WFFM Form in Page Editor

My project is in testing stage now. One error submitted has the behaviour like this: In Page Editor Mode, when user goes to a page with WFFM form included, it will give the yellow error page with message:

[InvalidOperationException: folder]
  Sitecore.Form.Core.Configuration.ThemesManager.GetThemeName(Item form, ID fieldID) +578
  Sitecore.Form.Core.Configuration.ThemesManager.GetThemeUrl(Item form, Boolean deviceDependant) +270
  Sitecore.Form.Core.Configuration.ThemesManager.ScriptsTags(Item form, Item contextItem) +49
  Sitecore.Form.Core.Configuration.ThemesManager.RegisterCssScript(Page page, Item form, Item contextItem) +184
  Sitecore.Form.Web.UI.Controls.SitecoreSimpleFormAscx.OnInit(EventArgs e) +233
  System.Web.UI.Control.InitRecursive(Control namingContainer) +186
  System.Web.UI.Control.AddedControl(Control control, Int32 index) +189
  Sitecore.Form.Core.Renderings.FormRender.OnInit(EventArgs e) +846
  System.Web.UI.Control.InitRecursive(Control namingContainer) +186
  System.Web.UI.Control.InitRecursive(Control namingContainer) +421
  System.Web.UI.Control.InitRecursive(Control namingContainer) +421
  System.Web.UI.Control.InitRecursive(Control namingContainer) +421
  System.Web.UI.Control.InitRecursive(Control namingContainer) +421
  System.Web.UI.Control.InitRecursive(Control namingContainer) +421
  System.Web.UI.Control.InitRecursive(Control namingContainer) +421
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2098

Here are some background information of this project. It’s is multi-site environment, where each site has it’s own form root. All form roots’ paths are configured in site definition. And there are security access setting for each site’s user. User can only see his own site’s form root folder.

Of course whenever an error occurs in testing environment, the first thing is to simulate it in development environment. Unfortunately, it’s not there. But I did notice one thing, the same error will not happen when access the item using super admin account. It gives a hint, the issue may related to access right.

Next thing is to check on the method – Sitecore.Form.Core.Configuration.ThemesManager.GetThemeName(Item form, ID fieldID).

private static string GetThemeName(Item form, ID fieldId)
{
    string str = string.Empty;
    if (Settings.UseThemeFromParent && ID.op_Equality(form.get_Parent().get_TemplateID(), IDs.FormFolderTemplateID))
        str = ((object) form.get_Parent().get_ID()).ToString();
    if (StringExtensions.IsNullOrEmpty(str))
        str = SiteUtils.GetFormsRootForSite(Context.get_Site());
    Item obj1 = form;
    if (ID.op_Inequality(form.get_TemplateID(), IDs.FormFolderTemplateID))
        obj1 = form.get_Database().GetItem(str);
    Assert.IsNotNull((object) obj1, "folder");
    if (string.IsNullOrEmpty(((BaseItem) obj1).get_Fields().get_Item(fieldId).get_Value()))
        return "Default";
    Item obj2 = form.get_Database().GetItem(((BaseItem) obj1).get_Fields().get_Item(fieldId).get_Value());
    if (obj2 == null || string.IsNullOrEmpty(obj2.get_Name()))
        return "Default";
    return obj2.get_Name();
}

Soon SiteUtils.GetFormsRootForSite(Context.Site) get my notice. “Context” is the most difficult / confusing / easy to get wrongly / hard to understand / … function. I should check my site definition. Yes, there’s really a difference for site definitions in development and testing environment. In testing environment, each site has its own hostName, but in development environment, they share the same one. So quickly request for new host name and apply them in development sites. Hooray, the error is now showing!

Now I can play around with it. In page’s content sublayout, I added a function to show SiteUtils.GetFormsRootForSite(Context.Site), and it gives ID {F1F7AAB6-C8CE-422F-A214-F610C109FA63}. It is /sitecore/system/Modules/Web Forms for Marketers/Website. Great, it explains why user gets error, because I didn’t give user read access of this item! After assign read access, the error is gone.

Lesson learned while resolving this issue:

  • Always keep development configuration synced with testing or even production environment, you’ll never know when the small difference will cause big trouble.
  • Give read access to Sitecore original items, even though you may not using it and keep it an empty folder.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s