I'm trying to add some extra drop down options and radio buttons to the contact form.
However I'm having trouble getting their values to appear in the email. What do I need to do to get these values to display? I've had a look at adding them to the RVContactFormMailer.asmx.cs file and have added the details to the RV-ContactForm.emailBody library item.
<link href="/css/RVContactForm.css" rel="stylesheet" type="text/css" /> <!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>--> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> <script type="text/javascript" src="/Scripts/json2.js"></script> <script type="text/javascript" src="/Scripts/RVContactForm.js"></script> <script type="text/javascript"> //custom error messages for this form fields. we defined them here and not in the js file because we need to use the dictionary items from the server.
var errName = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.error.name")' />"; var errCompany= "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.error.company")' />"; var errDigits = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.error.digits")' />"; var errPhone = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.error.phone")' />"; var errorEmail = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.error.email")' />"; var errState = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.error.state")' />"; var errSubject = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.error.subject")' />"; var errMessage = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.error.message")' />"; var thankYouHeaderText= "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.thankYouHeaderText")' />"; var thankYouMessageText = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.thankYouMessageText")' />"; var failureHeaderText = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.failureHeaderText")' />"; var failureMessageText = "<xsl:value-of select='umbraco.library:GetDictionaryItem("RV-ContactForm.failureMessageText")' />";
/* // custom error messages for this plugin. // change the text if you adding new form fields from different types (date, creditcard etc). jQuery.extend(jQuery.validator.messages, { required: "This field is required.", remote: "Please fix this field.", email: "Please enter a valid email address.", url: "Please enter a valid URL.", date: "Please enter a valid date.", dateISO: "Please enter a valid date (ISO).", number: "Please enter a valid number.", digits: "Please enter only digits.", creditcard: "Please enter a valid credit card number.", equalTo: "Please enter the same value again.", accept: "Please enter a value with a valid extension.", maxlength: jQuery.validator.format("Please enter no more than {0} characters."), minlength: jQuery.validator.format("Please enter at least {0} characters."), rangelength: jQuery.validator.format("Please enter a value between {0} and {1} characters long."), range: jQuery.validator.format("Please enter a value between {0} and {1}."), max: jQuery.validator.format("Please enter a value less than or equal to {0}."), min: jQuery.validator.format("Please enter a value greater than or equal to {0}.") }); */ </script>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Services; using System.Xml; using System.Xml.Linq; using System.Text; using System.Configuration; using System.Net; using System.Net.Mail; using System.Text.RegularExpressions;
namespace RVContactForm { public class MailerRequest { public string name; public string company; public string preferredContact; public string phone; public string email; public string state; public string subject; public string message; }
/// <summary> /// Send contact form data by mail. /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] // To allow this Web Service to be called from script, (using ASP.NET AJAX or JQuery), and return json formatted data. [ToolboxItem(false)] public class RVContactFormMailer : System.Web.Services.WebService {
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public void SendContactForm(MailerRequest req) {
if (strName==string.Empty) { throw new HttpRequestValidationException(strValidationErr); } /* if (strCompany==string.Empty) { throw new HttpRequestValidationException(strValidationErr); } */ if (strPhone!=string.Empty) { bool isNum = Regex.IsMatch(strPhone, "^\\d+(\\.\\d+)?$");
if (isNum==false || strPhone.Length<7) { throw new HttpRequestValidationException(strValidationErr); } } if (strEmailSubject==string.Empty) { throw new HttpRequestValidationException(strValidationErr); }
if (strEmailFrom!=string.Empty) { //Email Regex String Regex reg = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
// Check if there is NO match in Regex if (!reg.IsMatch(strEmailFrom)) { //Does not match RegEx - Invalid email address throw new HttpRequestValidationException(strValidationErr); } } if (strMessage==string.Empty) { throw new HttpRequestValidationException(strValidationErr); }
// Convert the form data into an js object var myMailerRequest = { name: $('#name').val(), company: $('#company').val(), preferredContact: $('#preferredContact').val(), phone: $('#phone').val(), email: $('#email').val(), state: $('#state').val(), subject: $('#subject').val(), message: $('#message').val(), nodeid: $("#RV_CurrentNodeId").val() }; // JSONify the js object - desirialize js object to MailerRequest object. the first param must be equal to the name of the input parameter in the web service method "SendContactForm" var data = JSON.stringify({ req: myMailerRequest });
if you see that all the values is sent properly except the field you added - probebly you are not get the value from this fields properly.
check your jquery syntax. (by the way, try to send the webservice static values and check if it send properly to you email. if so - again - you have syntax error).
// Convert the form data into an js object var myMailerRequest = { name: $('#name').val(), company: $('#company').val(), preferredContact: $('#preferredContact').val(), preferredPhone: $('#preferredPhone').val(), phone: $('#phone').val(), email: $('#email').val(), state: $('#state').val(), subject: $('#subject').val(), message: $('#message').val(), nodeid: $("#RV_CurrentNodeId").val() }; // JSONify the js object - desirialize js object to MailerRequest object. the first param must be equal to the name of the input parameter in the web service method "SendContactForm" var data = JSON.stringify({ req: myMailerRequest });
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Services; using System.Xml; using System.Xml.Linq; using System.Text; using System.Configuration; using System.Net; using System.Net.Mail; using System.Text.RegularExpressions;
namespace RVContactForm { public class MailerRequest { public string name; public string company; public string preferredContact; public string phone; public string email; public string state; public string subject; public string message; }
/// <summary> /// Send contact form data by mail. /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] // To allow this Web Service to be called from script, (using ASP.NET AJAX or JQuery), and return json formatted data. [ToolboxItem(false)] public class RVContactFormMailer : System.Web.Services.WebService {
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public void SendContactForm(MailerRequest req) {
if (strName==string.Empty) { throw new HttpRequestValidationException(strValidationErr); } /* if (strCompany==string.Empty) { throw new HttpRequestValidationException(strValidationErr); } */ if (strPhone!=string.Empty) { bool isNum = Regex.IsMatch(strPhone, "^\\d+(\\.\\d+)?$");
if (isNum==false || strPhone.Length<7) { throw new HttpRequestValidationException(strValidationErr); } } if (strEmailSubject==string.Empty) { throw new HttpRequestValidationException(strValidationErr); }
if (strEmailFrom!=string.Empty) { //Email Regex String Regex reg = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
// Check if there is NO match in Regex if (!reg.IsMatch(strEmailFrom)) { //Does not match RegEx - Invalid email address throw new HttpRequestValidationException(strValidationErr); } } if (strMessage==string.Empty) { throw new HttpRequestValidationException(strValidationErr); }
Adding extra drop down options and radio buttons
I'm trying to add some extra drop down options and radio buttons to the contact form.
However I'm having trouble getting their values to appear in the email. What do I need to do to get these values to display? I've had a look at adding them to the RVContactFormMailer.asmx.cs file and have added the details to the RV-ContactForm.emailBody library item.
Can anyone help?
Cheers,
JV
My XSLT:
My RVContactFormMailer.asmx.cs
RV-ContactForm.emailBody
you should also add this values to the js file called "RVContactForm".
in this file you actually send the values from the client side to the web service using Json. look for this line and add it your data:
update if its help.
Eran.
Thanks Eran,
I've updated my js file. But it's still not sending the results from the "preferredContact" and "state" options:
hi,
you should debug using firebug and see what exactly is send to the webservice.
you should see something like this.
if you see that all the values is sent properly except the field you added - probebly you are not get the value from this fields properly.
check your jquery syntax. (by the way, try to send the webservice static values and check if it send properly to you email. if so - again - you have syntax error).
Ok I've made a change to the XSLT file and now I have the following result:
This is the change in the XSLT file:
However I'm still not getting the 'preferredContact' or 'state' showing up in the email.
sorry but i didnt understand from your answer: did you put static values in the js to check if it gets to the asmx?
i mean in the line:
if yes, you should see in firebug all the values sent to the asmx. i want to know for sure so we know that the problem is in the asmx code.
Thanks
I am seeing all the values sent to the asmx in firebug, however it's not being sent in the email.
Here's my js file code:
Here's my asmx code:
hi,
in the asmx, try to change the lines:
to this line:
now you will see in your email if you get the right values to the asmx.
if you see the values: its means that something wrong in your email template that defined in the dictionary named "RV-ContactForm.emailBody".
is working on a reply...