7.3.7 AJAX contact form surface controller new page
Hi Everyone,
I've got a fairly straight forward AJAX contact form, which uses basically the same as my other sites, but using 7.3.7, the response is being posted back to a new page: /umbraco/Surface/Contact/SendEnquiry rather than the form
<script>
function ShowError() {
$("#status").removeClass();
$("#status").addClass("alert alert-error");
$("#status").html("<strong>Error!</strong> There was an error posting the contact form. Please try again later.");
}
function ShowSuccess() {
$("#target").removeClass();
$("#target").addClass("alert alert-success");
}
And my Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
using System.Net.Mail;
using System.Net;
using ActionMailer.Net.Mvc;
using IceSigns.Models;
namespace IceSigns.Controllers
{
public class ContactController : Umbraco.Web.Mvc.SurfaceController
{
[HttpPost]
[NotChildAction]
public ActionResult SendEnquiry(Contact form)
{
//umbraco.NodeFactory.Node contactNode = new umbraco.NodeFactory.Node(1049);
//string companyEmail = Convert.ToString(contactNode.GetProperty("contactFormEmail"));
string Honeybear = form.Honeybear;
string IsHuman = form.IsHuman;
string retValue = "<p class='intro'>There was an error submitting the form, please try again later.</p>";
if (!ModelState.IsValid)
{
return Content(retValue);
}
if (ModelState.IsValid)
{
if (!String.IsNullOrEmpty(Honeybear))
{
retValue = "<p class='intro'>Don't fill in the honeybear!</p>";
return Content(retValue);
}
else
{
retValue = "<p class='intro'><strong>Thank you!</strong> - your enquiry was submitted successfully. We will try to respond to your enquiry at the earliest opportunity.</p>";
new MailController().SendContactForm(form.Message, form.Email, form.Name, form.Telephone, form.Company).Deliver();
return Content(retValue);
}
}
return Content(retValue);
}
}
}
Oh, and I've added to my web.config as normal.
The emails are being sent, but as said, the response is being sent to a new page, rather than the form.
I had a similar problem. Besides adding the appsettings Kasper mentioned, I installed Microsoft.jQuery.Unobtrusive.Ajax nuget package and add a reference to the script in my template.
7.3.7 AJAX contact form surface controller new page
Hi Everyone,
I've got a fairly straight forward AJAX contact form, which uses basically the same as my other sites, but using 7.3.7, the response is being posted back to a new page: /umbraco/Surface/Contact/SendEnquiry rather than the form
Here's my view:
@using IceSigns.Models;
@{ HtmlHelper.ClientValidationEnabled = true; HtmlHelper.UnobtrusiveJavaScriptEnabled = true; var Node = Umbraco.Content(1060); }
@using (Ajax.BeginForm("SendEnquiry", "Contact", new AjaxOptions
{ HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "target", OnFailure = "ShowError()", OnSuccess = "ShowSuccess()" })) {
email: @Node.GetPropertyValue("siteEmail").ToString()
tel: @Node.GetPropertyValue("siteTelephoneNumber").ToString()
fax: @Node.GetPropertyValue("siteFaxNumber").ToString()
And my Controller:
using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Umbraco.Web.Mvc; using System.Net.Mail; using System.Net; using ActionMailer.Net.Mvc; using IceSigns.Models;
namespace IceSigns.Controllers { public class ContactController : Umbraco.Web.Mvc.SurfaceController {
}
Oh, and I've added to my web.config as normal.
The emails are being sent, but as said, the response is being sent to a new page, rather than the form.
edit: Not sure what's happened to the formatting?
Hello Craig
Not sure if i understand the question totally.
but du you have
In your web.config i've had some problems with ajax post if they are not there :)
I had a similar problem. Besides adding the appsettings Kasper mentioned, I installed Microsoft.jQuery.Unobtrusive.Ajax nuget package and add a reference to the script in my template.
is working on a reply...