Adding MVC Form Widget to Master Page With Form

Posted by Community Admin on 04-Aug-2018 16:45

Adding MVC Form Widget to Master Page With Form

All Replies

Posted by Community Admin on 20-Aug-2014 00:00

Hi,

I have been developing an MVC form widget to use on a pre-existing ASP.NET web forms application. The master page has a form. When I add the form widget to the home page, publish the page, and then fill-in the widget form with data and hit the submit button, I get the following javascript error:

  Cannot set property 'action' of undefined

The error occurs in this code block (which must be javascript added by Sitefinity). Error occurs at statement in bold:

<script type="text/javascript">
            function handleFormSubmitElements(elementName)
                var allSubmitElements = document.getElementById("quoteForm").getElementsByTagName(elementName);
                var elementCount = allSubmitElements.length;
                while(elementCount)
                    typeAttr = allSubmitElements[elementCount - 1].getAttribute("type");
                    if(typeAttr == "submit")
                        allSubmitElements[elementCount - 1].onclick = function()
                        document.forms["aspnetForm"].action = "/mvc-page-home-test/Index";
                            document.forms["aspnetForm"].method = "POST";
                        ;
                   
                    elementCount--;
               
           

            handleFormSubmitElements("input");
            handleFormSubmitElements("button");
        </script>

Can I not create a form widget that will work in a web forms application that already has a form? Can someone help me out here?

Thanks so much,

Mac

Posted by Community Admin on 25-Aug-2014 00:00

Hello Mac,

The problem comes from the default server form Id. The MVC widget expects that its ID is aspnetForm and tries to find it. However, probably the form on your master page/ template is with different Id. Please, ensure the main form is with the same Id. For reference, here is a default markup of a Frontend master page:

<%@ Page AutoEventWireup="true" Language="C#" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale = 1.0" />
</head>
<body>
    <form id="aspnetForm" runat="server">
        <div class="sfPublicWrapper" id="PublicWrapper" runat="server">
            <sf:SitefinityPlaceHolder ID="Body" runat="server"></sf:SitefinityPlaceHolder>
        </div>
    </form>
</body>
</html>

This is why aspnetForm is hard coded in the injected script reference.

Regards,
Nikola Zagorchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed