Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • James Joplin 11 posts 62 karma points
    Nov 08, 2012 @ 18:16
    James Joplin

    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 :

     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 values
            Dictionary<stringstring> formResults = new Dictionary<stringstring>();

    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 above
            string valueHTML = string.Empty;
            foreach (KeyValuePair<stringstring> 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>",

Please Sign in or register to post replies

Write your reply to: