0

I'm working on a migration project from 6.5 to 8.2. I've installed a clean WFFM 8.2 and I'm trying to refactor the existing code.

It adds the WFFM form programatically as follows:

ASCX

  <div runat="server" class="grid_13" id="OpeningFormDiv">
  </div>

ASCX.CS - original code

  FormRender Form = new FormRender
        {
            FormID = GetParameter("FormID"),                
            ReadQueryString = GetParameter("ReadQueryString"),
            FormTemplate = "/sitecore modules/web/Web Forms for Marketers/Control/SitecoreSimpleFormAscx.ascx"
        };
  OpeningFormDiv.Controls.Add(Form);

ASCX.CS - "new" code

  SitecoreSimpleForm form = new SitecoreSimpleForm(Sitecore.Context.Database.GetItem(GetParameter("FormID")));
  var test = new FormRender(form);
   OpeningFormDiv.Controls.Add(test);

the new code has the same effect (and basically does the same thing). both throw and exception stating that the innerItem is empty:

Server Error in '/' Application.

Value cannot be null.
Parameter name: innerItem

Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: innerItem

All the code samples I've found online are using this method, so I think I'm on the right track here. Does anyone have an idea what might be wrong? When debugging the FormId and Querystring parameters are retrieved correctly and the SitecoreSimpleForm is created as normal. The error occurs when the form is added to the controls of the div.

6
  • 1
    Can you see if the Context.Database is correct and all required items have been published? Commented Mar 20, 2017 at 13:04
  • I was thinking the same thing. I'm republishing the templates and layouts now... Commented Mar 20, 2017 at 13:06
  • Has the publishing fix the issue? Commented Mar 20, 2017 at 13:35
  • now I'm getting unrecognized GUId format. But I'm also seeing a broken links gutter, so It's probably some item linked in the form. At least the code is correct. thanks! Commented Mar 20, 2017 at 13:37
  • Hi Rueben. This question is a bit on a spin. I saw your updated question edit, but you should really post a new question under a separate headline. It is not related to "Adding a WFFM form programatically".
    – Mark Cassidy
    Commented Mar 20, 2017 at 16:00

1 Answer 1

1

The reason why innerItem may be null is because it is not found on the target database.

Try to perform a republish and see if the issue is fixed.

3
  • 1
    Just to note: Smart publish may be faster in this case Commented Mar 20, 2017 at 13:51
  • @AndreyBobrov, yes or even incremental publish Commented Mar 20, 2017 at 13:52
  • This was only part of the answer. the real issue was the tracking field which causes the unrecognized GUID format error. Commented Mar 20, 2017 at 14:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.