5

I have created a custom submit based on the below module:

https://www.nishtechinc.com/Blog/2018/April/Send-E-mail-Action-to-Sitecore-9-Forms

It went all hunky dory on my dev machine but when moved to our staging environment it started submitting twice and thus sending two emails. I added some logging to my custom code and it is definitely a submit of the same form as the SessionId, TemplateId etc. are all identical.

During my frantic googling I came across the below question on stack exchange which looks like the same problem but there wasn't an answer given.

Sitecore 9 Forms Custom Submit Model called twice

The bit I am missing is what happens between the form being submitted and it hitting the execute method on my submit action. Any pointers on where I can troubleshoot around that would be great.

I am stumped with the above so any help would be greatly appreciated. Please let me know if any more information is needed.

Cheers

Shaun

P.s This is my first time asking a question on StackExchange so please let me know if my question could have been clearer and/or more helpful.

8
  • is it enable Ajax Post check box? If is enabled can you disabled it and check again ? Commented Nov 19, 2020 at 15:07
  • @VladIobagiu Thanks for reply. Just tried the above and when submitting I get an error.
    – Shaun121
    Commented Nov 19, 2020 at 15:15
  • @VladIobagiu I will post the error above as it is too long for comments. Thanks for the advice I'll look at why my forms are erroring without Ajax
    – Shaun121
    Commented Nov 19, 2020 at 15:17
  • @VladIobagiu just realised that adding the error above may muddy the water somewhat so here's the error on this question: sitecore.stackexchange.com/questions/23759/…
    – Shaun121
    Commented Nov 19, 2020 at 15:20
  • when you submit do you see 2 formsbuilder in the network tab in Chrome/ Developer Tools , something like : formbuilder?fxb.FormItemId=5fd6197f-ffdb-4426-9298-07eaf4865b02&fxb.HtmlPrefix=fxb.24481816-6c0e-49fb-bf2b-2275e185ffb1 Commented Nov 19, 2020 at 15:32

3 Answers 3

1

I inherited some AJAX-enabled Forms from other developers. One form only sent a single request to (/formbuilder), the other sent a duplicate request.

For the Form item that worked properly (single request), the "Scripts" field had this value:

jquery-3.4.1.min.js|jquery.validate.min.js|jquery.validate.unobtrusive.min.js|form.validate.js|form.tracking.js|form.conditions.js

For the other Form, the same field has this value:

jquery-3.4.1.min.js|jquery.validate.min.js|jquery.validate.unobtrusive.min.js|**jquery.unobtrusive-ajax.min.js**|form.validate.js|form.tracking.js|form.conditions.js

The difference being the inclusion of jquery.unobtrusive-ajax.min.js.

When I removed this, I only saw a single request for both forms.

I also noted that I only saw a duplicate request when logged-into Sitecore, in Edge. In Chrome, or a Private Window, there was only one request, even when jquery.unobtrusive-ajax.min.js was included.

0

I had some problems with Sitecore forms submit when Ajax was enabled (not submit duplication though). The solution in was to edit: \Views\FormBuilder\Form.cshtml and add @Html.RenderFormStyles() above form definition and @Html.RenderFormScripts() below form definition like so:

@Html.RenderFormStyles()

@{
    using (Html.BeginRenderRouteForm(Model, IsPost))
    {
        @Html.AntiForgeryToken()
        @Html.Hidden(AttributeNames.FormItemId, Model.ItemId)
        @Html.ValidationSummary(true)
        @Html.RenderFields(Model)
        <input type="hidden" data-sc-fxb-condition value='@Html.RenderConditions(Model)' />
    }
}

@Html.RenderFormScripts()
1
  • This fix also fixed my problem where an ajax call on the form submission would result in an unstyled form being returned in the response. The url would be weird having "/formbuilder" being included in the address. I think this is actually a call to a Sitecore api. When I modified the Form.cshtml file as described, the form would validate and submit using ajax correctly.
    – AJM
    Commented Sep 22, 2021 at 7:08
0

Please check, how many times the forms scripts are getting loaded. We were having same scenario for ajax enabled checkbox and after checking the html by inspecting, the script reference was twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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