I have not ever had to submit a form in Sitecore before, in my previous experience I used WFFM, thus I didn't have to create or process forms.
My form is simply to take in some information and forward the information from the form via email, thus we are not saving the data to a database. Along with that I need to send back a confirmation note to my user
so, I have created two partial views (view Renderings) that I will use for this task. These view Renderings are components that sit inside of placeholders on my template sharing the page layout that I created for my site. These View renderings have their own datasource.
One of the View Renderings (FormGeneric.cshtml) contains the form below:
@model RenderingModel
@{
var formTitle = "";
var formSubTitle = "";
var formText = "";
var ImageUrl = "";
var buttonText = "";
try
{
formTitle = Model.Item.Fields["Heading"].Value;
formSubTitle = Model.Item.Fields["Sub Heading"].Value;
formText = Model.Item.Fields["Form Text"].Value;
var formImage = (Sitecore.Data.Fields.ImageField) Model.Item.Fields["Image"];
buttonText = Model.Item.Fields["Button Text"].Value;
if (formImage.Value != "" && formImage != null)
{
ImageUrl = Sitecore.Resources.Media.MediaManager.GetMediaUrl(formImage.MediaItem);
}
}
catch { }
}
<div class="container">
<div class="col-sm-6">
<h2>@formTitle</h2>
<p class="large-subhead">@formSubTitle</p>
<p>@formText</p>
<img class="img-responsive" src="@ImageUrl">
</div>
<div class="col-sm-6">
<form class="content-form">
@using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post))
{
<div class="form-group form-group-lg">
<input type="" class="form-control" id="" placeholder="Full Name">
</div>
<div class="form-group form-group-lg">
<input type="" class="form-control" id="" placeholder="Street Address">
</div>
<div class="form-group form-group-lg">
<input type="" class="form-control" id="" placeholder="City">
</div>
<div class="input-group input-group-lg">
<input type="text" class="form-control" aria-label="...">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">State <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="#">Option</a></li>
<li><a href="#">Option</a></li>
<li><a href="#">Option</a></li>
</ul>
</div><!-- /btn-group -->
</div><!-- /input-group -->
<div class="form-group form-group-lg">
<input type="" class="form-control" id="" placeholder="Zip/Postal Code">
</div>
<div class="input-group input-group-lg">
<input type="text" class="form-control" aria-label="...">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Country <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="#">Option</a></li>
<li><a href="#">Option</a></li>
<li><a href="#">Option</a></li>
</ul>
</div><!-- /btn-group -->
</div><!-- /input-group -->
@Html.Sitecore().FormHandler("GreatAmericanCampoutController", "SignUp")
<button type="submit" class="inline-btn">@buttonText</button>
}
</form>
</div>
</div>
and as you can see I have placed a line
@Html.Sitecore().FormHandler("GreatAmericanCampoutController", "SignUp")
I added a controller called "GreatAmericanCampoutController" under my "controllers" folder in my solution, there will be more processing in this controller, but I just wanted to test the redirect to the Confirmation page
namespace Website.Controllers
{
public class GreatAmericanCampoutController : Controller
{
// GET: GreatAmericanCampout
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult SignUp()
{
var options = new UrlOptions
{
AddAspxExtension = false,
LanguageEmbedding = LanguageEmbedding.Never
};
var pathInfo = LinkManager.GetItemUrl(PageContext.Current.Item.Children.FirstOrDefault(), options);
return RedirectToRoute(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, new { pathInfo = pathInfo.TrimStart(new char[] { '/' }) });
}
}
}
I created a partial view (FormConfirmation.cshtml) that contains my Confirmation message
@model RenderingModel
@{
var subject = "";
var textualContent = "";
var signatureLine = "";
try
{
subject = Model.Item.Fields["Subject"].Value;
textualContent = Model.Item.Fields["Textual Content"].Value;
signatureLine = Model.Item.Fields["Signature Line"].Value;
}
catch { }
}
<div class="container">
<div class="col-sm-12 col-md-6 col-lg-9">
<h2>@subject</h2>
<br />
<p>
@textualContent
</p>
<br />
<br />
<p>Sincerely,
<br />
<br />
@signatureLine
</p>
</div>
</div>
when I press the "submit" button ... Nothing happens. I don't know if it just can't locate the controller or what.
I have enclosed an illustration of my Visual Studio Solution