Adding MVC Form Widget to Master Page With Form
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
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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
>