I added a small tweak to the GetMailContent function to easily add additional fields to the output HTML. It keeps you from having to modify the long format string.
Fields in this Example :
var first = HttpUtility.HtmlEncode(HttpContext.Current.Request["first-req"]);
var last = HttpUtility.HtmlEncode(HttpContext.Current.Request["last-req"]);
var school = HttpUtility.HtmlEncode(HttpContext.Current.Request["school-req"]);
var phone = HttpUtility.HtmlEncode(HttpContext.Current.Request["phone-req"]);
var email = HttpUtility.HtmlEncode(HttpContext.Current.Request[page.FormVariables.EmailFieldName]);
var message = HttpUtility.HtmlEncode(HttpContext.Current.Request[page.FormVariables.MessageFieldName]).Replace("\n", "<br />");
Create a Dictionary to hold them :
// create a dictionary to hold our valuesDictionary<string, string> formResults = newDictionary<string, string>();
Add Fields :
// slap data into our dictionary// dictionary is fieldName, fieldValue
formResults.Add("Name", first + " " + last);
formResults.Add(page.FormVariables.Email, email);
formResults.Add("Phone Number", phone);
formResults.Add("School", school);
formResults.Add(page.FormVariables.Message, message);
formResults.Add("Interested In", GetCheckboxStatus());
// add more fields here!
Build Form Label / Form Values :
// build our template string from our fields abovestring valueHTML = string.Empty;
foreach (KeyValuePair<string, string> formItem in formResults)
{
// build our table row with the form field name
valueHTML += string.Format("<tr><td valign=\"top\"><p><strong>{0}</strong></p></td><td valign=\"top\"><p>{1}</p></td></tr>", formItem.Key, formItem.Value);
}
Create mailContent string :
var mailContent = string.Format(
"{0}<br /><br /><table>{1}</table>",
mailIntroText,
valueHTML
);
Adding Additional Fields Easily
I added a small tweak to the GetMailContent function to easily add additional fields to the output HTML. It keeps you from having to modify the long format string.
Fields in this Example :
Create a Dictionary to hold them :
Add Fields :
Build Form Label / Form Values :
Create mailContent string :
is working on a reply...