4

On my local environment all WFFM forms are working ok, however on our test environment when any form is submitted we get the error:

An item with the same key has already been added.

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.ArgumentException: An item with the same key has already been added.

Source Error:

Line 24:     if (!IsPost)
Line 25:     {
Line 26:       queryString.Add("wffm." + Constants.FormItemId, Model.Item.ID.ToGuid());
Line 27:       queryString.Add("wffm." + Constants.Id, Model.UniqueId);
Line 28:     }

Source File: D:\home\site\wwwroot\Views\Form\EditorTemplates\FormViewModel.cshtml Line: 26

Note: I have tried uncehcking the field on the form Is Ajax Mvc Form and this seems to resolve the issue.

Is there some configuration setting which could be causing this, since there is no difference in the form content itself between the two environments.

  • You seem to be adding the query string key "wffm." twice. – James Walford Apr 21 '17 at 12:24
  • 1
    That's not my code BTW, its the MVC rendering used by WFFM. Also the code is using "wffm." + Constants.FormItemId so it is appending the ID of the form to the end of the query string. – Matthew Dresser Apr 21 '17 at 12:56
  • 1
    check if some earlier code is adding a query string with the key "wffm." + Constants.FormItemId - that is the line it is failing on. Also - what are the values of Constants.FormItemId and Constants.Id - do they come from config or hard coded values? – Richard Seal Apr 21 '17 at 13:29
  • 1
    do you have url rewriting on test environment? – Vlad Iobagiu Apr 21 '17 at 14:54
  • 1
    can you verify if this one is the problem? enable url rewrite locally and try to see if it's working. – Vlad Iobagiu Apr 21 '17 at 15:34
5

The issue turned out to be due to a custom 404 error handler (Sitecore Climber was on the right track when he mentioned about the IIS rewrite module - redirects can mess up WFFM!). It was intercepting requests (with a httpRequestBegin pipeline handler) and returning the 404 page content. The solution was to change the 404 handler to ignore requests where the URL started with /form.

Note: if you create a 404 handler, make sure it can ignore certain paths where a sitecore item is not resolved, otherwise you will break lots of things in Sitecore!

| improve this answer | |
  • we had a custom item resolver which was taking the /formbuilder url (after submitting the form) and redirecting to itself by lowering the URL, due to this same URL was being hit twice and was causing the same query string to be added twice hence causing the error "Item with the same key has already been added" – Prashant Tomar Feb 18 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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