I am struggling to get a form working in the framework installation. I have copied what has been done in contact form and the I cant get the HttpPost method to fire. My model, controller and partial view is as below:
namespace Umbraco.Extensions.Models.Form
{
public class NewsletterSignupModel
{
public string Name { get; set; }
public string Email { get; set; }
public string Telephone { get; set; }
public DateTime DOB { get; set; }
public string AttendEventList { get; set; }
public string NewsList { get; set; }
public string HostEventList { get; set; }
public string PageHeading { get; set; }
public HtmlString PageSummary { get; set; }
public HtmlString PageIntroduction { get; set; }
public string FormHeading { get; set; }
public HtmlString FormSummary { get; set; }
}
}
namespace Umbraco.Extensions.Controllers
{
public class NewsletterSignupController : FormController
{
[DonutOutputCache(CacheProfile = "OneDay")]
public ActionResult NewsletterSignup()
{
var baseModel = GetModel<BaseModel>();
return CurrentTemplate(baseModel);
}
[HttpPost]
public ActionResult SendNewsletter(NewsletterSignupModel model)
@using (Html.BeginUmbracoForm("SendNewsletter", "NewsletterSignupController", null, new { @id = "newsletterSignupForm" }))
{
<div class="row">
<div class="col-sm-6 form-group">
<label>Name*</label>
<input type="text" id="Name" class="form-control" name="Name" placeholder="Please enter your name" data-bv-notempty="true" data-bv-notempty-message="Name is required">
<input type="Email" class="form-control" name="Email" placeholder="Please enter your email" data-bv-emailaddress-message="Invalid email address" data-bv-notempty="true" data-bv-notempty-message="Email address is required">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<label>Phone*</label>
<input type="tel" id="Telephone" name="Telephone" class="form-control" placeholder="Please enter your phone number" data-bv-notempty="true" data-bv-notempty-message="Email address is required">
</div>
<div class="col-sm-6 col-md-3 form-group">
<label>Date of birth*</label>
<div class="form-control styled-date">
<input type="text" id="DOB" class="form-control datepicker datepicker-dob" placeholder="DD/MM/YYYY" name="DOB" data-bv-notempty="true" data-bv-notempty-message="Date of birth is required">
Need help in Custom Form
Hi Guys,
I am struggling to get a form working in the framework installation. I have copied what has been done in contact form and the I cant get the HttpPost method to fire. My model, controller and partial view is as below:
namespace Umbraco.Extensions.Models.Form
{
public class NewsletterSignupModel
{
public string Name { get; set; }
public string Email { get; set; }
public string Telephone { get; set; }
public DateTime DOB { get; set; }
public string AttendEventList { get; set; }
public string NewsList { get; set; }
public string HostEventList { get; set; }
public string PageHeading { get; set; }
public HtmlString PageSummary { get; set; }
public HtmlString PageIntroduction { get; set; }
public string FormHeading { get; set; }
public HtmlString FormSummary { get; set; }
}
}
namespace Umbraco.Extensions.Controllers
{
public class NewsletterSignupController : FormController
{
[DonutOutputCache(CacheProfile = "OneDay")]
public ActionResult NewsletterSignup()
{
var baseModel = GetModel<BaseModel>();
return CurrentTemplate(baseModel);
}
[HttpPost]
public ActionResult SendNewsletter(NewsletterSignupModel model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
//Set the fields that need to be replaced.
var formFields = new Dictionary<string, string>
{
{"Name", model.Name},
{"Email", model.Email},
{"Telephone", model.Telephone},
{"DOB", model.DOB.Date.ToShortDateString()},
{"AttendEventList", model.AttendEventList},
{"NewsList",model.NewsList},
{"HostEventList", model.HostEventList}
};
//Send the e-mail with the filled in form data.
ProcessForms(formFields, EmailType.NewsletterSignUp, "emailUser", "emailCompany");
//Redirect to the succes page.
var child = CurrentPage.Children.FirstOrDefault();
if (child != null)
{
return RedirectToUmbracoPage(child);
}
return RedirectToCurrentUmbracoPage();
}
}
}
@using Umbraco.Web;
@using Umbraco.Extensions.Utilities;
@using Umbraco.Extensions.Models.Form;
@inherits Umbraco.Web.Mvc.UmbracoViewPage<NewsletterSignupModel>
<!-- Newsletter signup page -->
<section class="fullwidth form-validate form-spaced">
<div class="container container-border">
<div class="panel-intro">
<h1>@Model.PageHeading</h1>
<p>@Html.Raw(Model.PageSummary)</p>
</div>
<form>
<h3>@Model.FormHeading</h3>
@*@using (Html.BeginUmbracoForm("SendNewsletter", "NewsletterSignup"))*@
@using (Html.BeginUmbracoForm("SendNewsletter", "NewsletterSignupController", null, new { @id = "newsletterSignupForm" }))
{
<div class="row">
<div class="col-sm-6 form-group">
<label>Name*</label>
<input type="text" id="Name" class="form-control" name="Name" placeholder="Please enter your name" data-bv-notempty="true" data-bv-notempty-message="Name is required">
</div>
<div class="col-sm-6 form-group">
<label>Email*</label><span class="pull-right">* REQUIRED</span>
<input type="Email" class="form-control" name="Email" placeholder="Please enter your email" data-bv-emailaddress-message="Invalid email address" data-bv-notempty="true" data-bv-notempty-message="Email address is required">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<label>Phone*</label>
<input type="tel" id="Telephone" name="Telephone" class="form-control" placeholder="Please enter your phone number" data-bv-notempty="true" data-bv-notempty-message="Email address is required">
</div>
<div class="col-sm-6 col-md-3 form-group">
<label>Date of birth*</label>
<div class="form-control styled-date">
<input type="text" id="DOB" class="form-control datepicker datepicker-dob" placeholder="DD/MM/YYYY" name="DOB" data-bv-notempty="true" data-bv-notempty-message="Date of birth is required">
</div>
</div>
</div>
<h3>Tick all that apply</h3>
<div class="row">
<div class="col-sm-6 form-group">
<h5>News</h5>
<div class="checkbox">
<label>
<input type="checkbox" value="" name="AttendEventList">
Option one is this and that—be sure to include why it's great
</label>
</div>
<div class="checkbox disabled">
<label>
<input type="checkbox" value="">
Option two is disabled
</label>
</div>
<h5>News</h5>
<div class="checkbox">
<label>
<input type="checkbox" value="" name="NewsList">
Option one is this and that—be sure to include why it's great
</label>
</div>
<div class="checkbox disabled">
<label>
<input type="checkbox" value="">
Option two is disabled
</label>
</div>
</div>
<div class="col-sm-6 form-group">
<h5>News</h5>
<div class="checkbox">
<label>
<input type="checkbox" value="" name="HostEventList">
Option one is this and that—be sure to include why it's great
</label>
</div>
<div class="checkbox disabled">
<label>
<input type="checkbox" value="">
Option two is disabled
</label>
</div>
</div>
</div>
<div class="row row-form-btn">
<div class="col-sm-4 col-md-3 col-sm-offset-6 form-group">
<button type="submit" class="btn btn-form">Send</button>
</div>
</div>
}
</form>
</div>
</section>
Anyone can help on this please?
Its ok, I got it working. Thanks
care to explain what the issue was and how you fixed it?
I had "NewsletterSignupController" in the BeingUmbraco form, it should have been just "NewsletterSignup"
is working on a reply...