Jump to content

Checkboxes - website contact form

Recommended Posts

The checkbox in the following form isn't working.The response of ON or OFF needs to be sent within the email message. It currently only displays OFF in the email even if the check box is checked (ON).Any help would be greatly appreciated, Thank you.CDOSYS-transporter.asp

<%@ LANGUAGE="VBSCRIPT" %><% option explicit %><% Response.Buffer = True %><%'Declaring VariablesDim smtpserver,youremail,youremailcc,yourpassword,Cont  actUs_Name,ContactUs_EmailDim ContactUs_Subject,ContactUs_Body,Action,IsError,Co  ntactUs_Newsletter	' Edit these 3 values accordinglysmtpserver = "mail.example.com"youremail = "info@example.com"yourpassword = "password1234"	' Grabbing variables from the form postContactUs_Name = Request("ContactUs_Name")ContactUs_Email = Request("ContactUs_Email")ContactUs_Subject = Request("ContactUs_Subject")ContactUs_Body = Request("ContactUs_Body")ContactUs_Newsletter = Request("ContactUs_Newsletter")if ContactUs_Newsletter <> "" then  ContactUs_Newsletter = "ON"else ContactUs_Newsletter = "OFF"end if Action = Request("Action")%><%If Action = "SendEmail" Then		Dim strBody		' Here we create a nice looking html body for the email	strBody = strBody & "<font face=""Arial"">Contact Us Form submitted at " & Now() &  vbCrLf & "<br><br>"	strBody = strBody & "From http://" & Request.ServerVariables("HTTP_HOST") &  vbCrLf & "<br>"	strBody = strBody & "IP " & Request.ServerVariables("REMOTE_ADDR") & vbCrLf & "<br>"	strBody = strBody & "Name" & " : " & " " & Replace(ContactUs_Name,vbCr,"<br>") & "<br>"	strBody = strBody & "Email" & " : " & " " & Replace(ContactUs_Email,vbCr,"<br>") & "<br>"	strBody = strBody & "Subject" & " : " & " " & Replace(ContactUs_Subject,vbCr,"<br>") & "<br>"	strBody = strBody & "<br>" & Replace(ContactUs_Body,vbCr,"<br>") & "<br>"	strBody = strBody & "Subscribe to Newsletter" & " : " & " " & Replace(ContactUs_Newsletter,vbCr,"<br>") & "<br>"	strBody = strBody & "</font>"		Dim ObjSendMail	Set ObjSendMail = CreateObject("CDO.Message") 	 	'This section provides the configuration information for the remote SMTP server.	 	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60	 	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = youremail	ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = yourpassword	 	ObjSendMail.Configuration.Fields.Update	 	'End remote SMTP server configuration section==	 	ObjSendMail.To = youremail	ObjSendMail.Cc = youremailcc	ObjSendMail.Subject = ContactUs_Subject	ObjSendMail.From = ContactUs_Email	 	' we are sending a html email.. simply switch the comments around to send a text email instead	ObjSendMail.HTMLBody = strBody	'ObjSendMail.TextBody = strBody	 	ObjSendMail.Send	 	Set ObjSendMail = Nothing 	%><% Else %><% End If %>


<html><head><title>Contact Us Form</title></head><body style="font-family: Arial; font-size: 12px"><form action="CDOSYS-transporter.asp" method="post">	<input type="hidden" name="Action" value="SendEmail">	<font size="2">Contact Us:</font> 	<br><br>	<table border="0" cellspacing="1">		<tr>			<td valign="top">				Name:			</td>			<td colspan="2">				<input type="text" name="ContactUs_Name" size="35" value="<% =ContactUs_Name %>">			</td>		</tr>		<tr>			<td valign="top">				Email:			</td>			<td colspan="2">				<input type="text" name="ContactUs_Email" size="35" value="<% =ContactUs_Email %>">			</td>		</tr>		<tr>			<td valign="top">				Subject:			</td>			<td colspan="2">				<input type="text" name="ContactUs_Subject" value="<% =ContactUs_Subject %>" size="35">			</td>		</tr>		<tr>			<td valign="top">				Message:			</td>			<td valign="top">				<textarea rows="10" name="ContactUs_Body" cols="40"><% =ContactUs_Body %></textarea>			</td>		</tr>		<!-- newsletter subscription checkbox START -->		<tr>			<td valign="top">				Subscribe to our Newsletter:			</td>			<td colspan="2">				<input type="checkbox" name="ContactUs_Newsletter" value="<% =ContactUs_Newsletter %>">			</td>		</tr>		   		<!-- newsletter subscription checkbox END -->				<tr>			<td valign="top"> 							</td>			<td colspan="2">				<input type="submit" class="submit" value="Send Message">			</td>		</tr>	</table></form></body></html>

Link to post
Share on other sites

If you don't think this is working:

if ContactUs_Newsletter <> "" then  ContactUs_Newsletter = "ON"else ContactUs_Newsletter = "OFF"end if

Then print the value that you're testing out so you can verify it. You'll find that it is in fact working. The problem is that you're not giving the checkbox a value, so it always submits an empty string.

Link to post
Share on other sites

Thank you for the reply.If the check box is checked (ON) within the form, once it's submitted, it only displays OFF in the email that is sent.If I place two instances of the 'exact same check box' on the form, then check both checkboxes, the sent email displays as the checkbox is checked (ON).I dont understand how to "give the checkbox a value" as you suggested even though i seem to be 'checking' the checkbox.Would you be so kind to provide a solution to fix this issue? Many thanks.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...