Radio buttons on contact form

Jun 28, 2011 at 10:59 PM

I've created some radio buttons on my contact form for 'Customer Type) by modifying ajax.cs, __utility/forms/contact.view and __utility/emails/contact.view but it doesn’t pass the selection into the email. I get the email with Customer: $custtype.

Is there something else I need to do?

Jul 1, 2011 at 6:02 AM

Could you post the code that you've modified?

Jul 1, 2011 at 11:31 AM

Thanks for looking Charles.

Here are the 3 files I've modified. It's just to add 3 radio buttons for customer type (custtype). The form looks OK but the email arrives with 'Customer: $custtype.'

case "newContactMessage":
                string subject = context.Request.Form["subject"];                string email = context.Request.Form["email"];                string name = context.Request.Form["name"];                string message = context.Request.Form["message"];                string custtype = context.Request.Form["custtype"];
                if (string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(message))                {                    context.Response.Write("All of the fields are required, your message has not been sent");                    context.Response.End();                    return;                }
                if (!Regex.IsMatch(email, @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", RegexOptions.IgnoreCase))                {                    context.Response.Write("The email address you entered is not valid");                    context.Response.End();                    return;                }
                EmailTemplateToolboxContext templateContext = new EmailTemplateToolboxContext();                templateContext.Put("subject", context.Server.HtmlEncode(subject));                templateContext.Put("email", context.Server.HtmlEncode(email));                templateContext.Put("name", context.Server.HtmlEncode(name));                templateContext.Put("message", Util.ConvertTextToHTML(message));                templateContext.Put("custtype", context.Server.HtmlEncode(custtype));                templateContext.Put("ip", context.Request.UserHostAddress);
                EmailTemplate et = new EmailTemplate();                et.Subject = "Contact Request: " + subject + " " + name;                et.Context = templateContext;                et.From = email;                et.TemplateName = "contact.view";
                Log.Info("Contact Received", "Subject: {0}\nFrom:{1} ({2}) \n{3} \n\n{4} \nIP:{5}\n\n", subject, name, email, custtype, message, context.Request.UserHostAddress);
                foreach (IGraffitiUser user in GraffitiUsers.GetUsers(GraffitiUsers.AdminRole))                {                    et.To = user.Email;                    Emailer.Send(et);                }
                context.Response.Write("Your message was sent. Thanks!");


<div class="form_field_pair custtype"> <div class="form_field_name"><label for="custtype"></label></div> <div class="form_field"> <input type="radio" name="custtype" value="wholesaler" tabindex="4"/> Wholesaler <input type="radio" name="custtype" value="retailer" tabindex="5"/> Retailer <input type="radio" name="custtype" value="householder" tabindex="6"/> Householder </div> </div>


<html><body> <h1>You have contact request!</h1><br /> <div style="text-align:center;"> <div style="text-align:left;width:90%;border:1px solid #000;padding:10px;"> <p> <strong>$subject</strong><br /> From: $name<br /> Email:($email)<br /> Customer: $custtype<br /> IPAddress: $ip<br /> </p>
$message<br /> </div></div><p style="color:gray">You were sent this message because you are listed as an Editor on the site $settings.Title</p></body></html>

Jul 3, 2011 at 5:44 AM

I tried this and it worked fine for me.

After you made these changes (specifically, to ajax.cs) did you recompile the code and redeploy the .dlls?