Developer forum

Forum » CMS - Standard features » Forms for editors use Default template when submitting even if page is selected

Forms for editors use Default template when submitting even if page is selected

Kasper Pedersen
Reply

Hello, I have a site where i have a form in the footer. I have selected a page to redirect to on submit. But it keeps scrolling down to the footer which I believe is unintentional since we want the user to see the confirmation page.

 

 

I can see that the RenderReceipt method in Dynamicweb.Forms.Frontend loads from "../../Admin/Module/BasicForms/DefaultConfirmationTemplate.cshtml".

This template has the script that does the unintended scrolling. 

<script type="text/javascript">
    window.scroll(0, findElementPosition(document.getElementById(@submitId)));
 
    function findElementPosition(obj) {
        var curtop = 0;
        if (obj.offsetParent) {
            do {
                curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
            return [curtop];
        }
    }
</script>

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

How did the form end up in the footer - that sounds like the real bug...? 

The receipt template is shown where the form is - and then it scrolls to where the receipt is. This is the behavior you would expect when you have regular page with a form, maybe below the fold, and then scrolls to where the receipt is.

Again, I cannot figure out how the form ended in the footer - but on the form app you can overwrite the default receipt template, and insert a version without the JS.

 
Kasper Pedersen
Reply

Hello Nicolai, it is in the footer because i placed it there. It's a newsletter subscription form and i am using the forms for editors module. Well the real issue here is that I have chosen to redirect to a page when submitting and the site loads fine and then scrolls to the form in the footer. I would think that when i haven't chosen Use confirmation template but redirect to page, then a template wouldn't be used. But i see that when Use confirmation template isn't set it uses the Default "../../Admin/Module/BasicForms/DefaultConfirmationTemplate.cshtml".

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

The form app will render a receipt if you have receipt information (s=...&pid=...) in the URL that fits the form and its paragraph. So in this case you have the same paragraph on all pages? 

Apps are not designed to live in a paragraph that is repeated in the footer on all pages...

A simple workaround would be something like this on the page you use for receipt - you can render this in the template only if the s parameter is in the querystring:
 

(function () {
  const url = new URL(window.location.href);

  if (url.searchParams.has("s")) {
    url.searchParams.delete("s");

    // If no params left, remove the "?" entirely
    const newUrl = url.pathname + (url.searchParams.toString() ? "?" + url.searchParams.toString() : "") + url.hash;

    window.location.replace(newUrl);
  }
})();

Or rename this element in the dom before the script r

 

You must be logged in to post in the forum