public override ActionResult Index() { bool formSubmit; if (bool.TryParse(Convert.ToString(TempData["FormSubmit"]), out formSubmit) && formSubmit) { return(PartialView("Submitted")); } return(CurrentItem.GetTokens("Form").Any(dt => dt.Is("FormSubmit")) ? PartialView("Form") : PartialView()); }
public override ActionResult Index() { bool formSubmit; if (Boolean.TryParse(Convert.ToString(TempData["FormSubmit"]), out formSubmit) && formSubmit) { return(PartialView("Submitted", CurrentItem)); } ViewData["hasSubmit"] = CurrentItem.GetTokens("Form").Any(dt => dt.Is("FormSubmit")); return(PartialView(CurrentItem)); }
public ActionResult Submit(FormCollection collection) { var mm = new MailMessage(CurrentItem.MailFrom, CurrentItem.MailTo.Replace(";", ",")); mm.Subject = CurrentItem.MailSubject; mm.Headers["X-FreeForm-Submitter-IP"] = Request.UserHostName; mm.Headers["X-FreeForm-Submitter-Date"] = N2.Utility.CurrentTime().ToString(); using (var sw = new StringWriter()) { sw.WriteLine(CurrentItem.MailBody); foreach (var token in CurrentItem.GetTokens("Form").Where(dt => dt.Name.StartsWith("Form", StringComparison.InvariantCultureIgnoreCase))) { var components = token.GetComponents(); string name = components[0]; name = token.Value ?? token.GenerateInputName(); if (token.Is("FormSubmit")) { continue; } else if (token.Is("FormFile")) { name = token.Value ?? token.GenerateInputName(); if (Request.Files[name] == null) { continue; } var postedFile = Request.Files[name]; if (postedFile.ContentLength == 0) { continue; } var fileName = Path.GetFileName(postedFile.FileName); sw.WriteLine(name + ": " + fileName + " (" + (int)(postedFile.ContentLength / 1024) + "kB)"); mm.Attachments.Add(new Attachment(postedFile.InputStream, fileName, postedFile.ContentType)); } else if (token.Is("FormInput") || token.Is("FormTextarea")) { name = token.Value ?? token.GenerateInputName(); var value = collection[name]; sw.WriteLine(name + ": " + value); } else { name = token.GetOptionalInputName(0, 1); var value = collection[name]; sw.WriteLine(name + ": " + value); } } mm.Body = sw.ToString(); } mailSender.Send(mm); TempData.Add("FormSubmit", true); return(RedirectToParentPage()); }
public ActionResult Submit(FormCollection collection) { var mm = new MailMessage(CurrentItem.MailFrom, CurrentItem.MailTo.Replace(";", ",")); mm.Subject = CurrentItem.MailSubject; mm.Headers["X-FreeForm-Submitter-IP"] = Request.UserHostName; mm.Headers["X-FreeForm-Submitter-Date"] = DateTime.Now.ToString(); using (var sw = new StringWriter()) { sw.WriteLine(CurrentItem.MailBody); var tokens = CurrentItem.GetTokens("Form").ToList(); // these are processed in goups var radioTokens = new Dictionary <string, List <DisplayableToken> >(); var checkboxTokens = new Dictionary <string, List <DisplayableToken> >(); foreach (var radioToken in tokens.Where(x => x.Is("FormRadio"))) { var helper = new RadioTokenHelper(radioToken); if (!helper.IsValid) { continue; } if (radioTokens.ContainsKey(helper.GetFormName())) { radioTokens[helper.GetFormName()].Add(radioToken); } else { radioTokens.Add(helper.GetFormName(), new List <DisplayableToken> { radioToken }); } } foreach (var checkboxToken in tokens.Where(x => x.Is("FormCheckbox"))) { var helper = new CheckboxTokenHelper(checkboxToken); if (!helper.IsValid) { continue; } if (checkboxTokens.ContainsKey(helper.GetFormName())) { checkboxTokens[helper.GetFormName()].Add(checkboxToken); } else { checkboxTokens.Add(helper.GetFormName(), new List <DisplayableToken> { checkboxToken }); } } foreach (var token in tokens.Where(dt => dt.Name.StartsWith("Form", StringComparison.InvariantCultureIgnoreCase))) { if (token.Is("FormSubmit")) { continue; } if (token.Is("FormCheckbox")) { var helper = new CheckboxTokenHelper(token); if (!helper.IsValid) { continue; } // only process if it is the last checkbox with this name var name = helper.GetFormName(); var checkboxes = checkboxTokens[name]; if (checkboxes.IndexOf(token) == (checkboxes.Count - 1)) { sw.WriteLine(name + ": " + collection[name]); } } else if (token.Is("FormFile")) { var helper = new FileTokenHelper(token); if (!helper.IsValid) { continue; } var name = helper.GetFormName(); if (Request.Files[name] == null) { continue; } var postedFile = Request.Files[name]; if (postedFile.ContentLength == 0) { continue; } var fileName = Path.GetFileName(postedFile.FileName); sw.WriteLine(name + ": " + fileName + " (" + (int)(postedFile.ContentLength / 1024) + "kB)"); mm.Attachments.Add(new Attachment(postedFile.InputStream, fileName, postedFile.ContentType)); } else if (token.Is("FormInput")) { var helper = new InputTokenHelper(token); if (!helper.IsValid) { continue; } var name = helper.GetFormName(); sw.WriteLine(name + ": " + collection[name]); } else if (token.Is("FormRadio")) { var helper = new RadioTokenHelper(token); if (!helper.IsValid) { continue; } // only process if it is the last radio button with this name var name = helper.GetFormName(); var radios = radioTokens[name]; if (radios.IndexOf(token) == (radios.Count - 1)) { sw.WriteLine(name + ": " + collection[name]); } } else if (token.Is("FormSelect")) { var helper = new SelectTokenHelper(token); if (!helper.IsValid) { continue; } var name = helper.GetFormName(); sw.WriteLine(name + ": " + collection[name]); } else if (token.Is("FormTextarea")) { var helper = new FreeTextareaTokenHelper(token); if (!helper.IsValid) { continue; } var name = helper.GetFormName(); sw.WriteLine(name + ": " + collection[name]); } } mm.Body = sw.ToString(); } try { mailSender.Send(mm); } catch (Exception ex) { Trace.WriteLine("Free form send email error:" + ex.Message); } if (!CurrentItem.UseAjax) { TempData.Add("FormSubmit", true); return(RedirectToParentPage()); } return(PartialView("Submitted", CurrentItem)); }
public ActionResult Submit(FormCollection collection) { var mm = new MailMessage(CurrentItem.MailFrom, CurrentItem.MailTo.Replace(";", ",")); mm.Subject = CurrentItem.MailSubject; mm.Headers["X-FreeForm-Submitter-IP"] = Request.UserHostName; mm.Headers["X-FreeForm-Submitter-Date"] = Utility.CurrentTime().ToString(); using (var sw = new StringWriter()) { sw.WriteLine(CurrentItem.MailBody); foreach ( var token in CurrentItem.GetTokens("Form").Where(dt => dt.Name.StartsWith("Form", StringComparison.InvariantCultureIgnoreCase))) { var components = token.GetComponents(); var name = components[0]; name = token.Value ?? token.GenerateInputName(); if (token.Is("FormSubmit")) { } else if (token.Is("FormFile")) { name = token.Value ?? token.GenerateInputName(); if (Request.Files[name] == null) { continue; } var postedFile = Request.Files[name]; if (postedFile.ContentLength == 0) { continue; } var fileName = Path.GetFileName(postedFile.FileName); sw.WriteLine(name + ": " + fileName + " (" + postedFile.ContentLength / 1024 + "kB)"); mm.Attachments.Add(new Attachment(postedFile.InputStream, fileName, postedFile.ContentType)); } else if (token.Is("FormInput") || token.Is("FormTextarea")) { name = token.Value ?? token.GenerateInputName(); var value = collection[name]; sw.WriteLine(name + ": " + value); } else { name = token.GetOptionalInputName(0, 1); var value = collection[name]; sw.WriteLine(name + ": " + value); // Assumption: any custom form input tokens with type=email are to be added to the reply-to list. if (components.Length >= 2 && string.Equals(components[1], "email", StringComparison.InvariantCultureIgnoreCase) && !string.IsNullOrWhiteSpace(value)) { try { var address = new MailAddress(value); // Prevent values with spaces from being interpreted as valid (see https://stackoverflow.com/a/1374644) if (value == address.Address) { mm.ReplyToList.Add(address); } } catch (FormatException) { } } } } mm.Body = sw.ToString(); } mailSender.Send(mm); TempData.Add("FormSubmit", true); return(RedirectToParentPage()); }