I have a Web form and although I have completed all form fields as part of a test, I get the error:
Quote:
You did not enter a message.
.
Yet, I know that I have, in fact, entered a message.
I deliberately omitted input in the email field while again typing in a few words in the message field and got the message:
Quote:
You did not enter a valid email address.
You did not enter a message.
So there is something wrong with the message field. I have this in my code which all seems to work:
Code:
If Action = "SendEmail" Then
' Here we quickly check/validate the information entered
' These checks could easily be improved to look for more things
If IsValidEmail(ContactUs_Email) = "False" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a valid email address.</font><br>")
End If
If ContactUs_Name = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a name.</font><br>")
End If
If ContactUs_Subject = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a subject.</font><br>")
End If
If ContactUs_Body = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a message.</font><br>")
End If
If WSP_CheckImageCode() <> "OK" Then
Response.Write "<font color=""red"">The image code you have entered is incorrect. Please click the 'Back' button of your browser and type the correct one.</font><br>"
Response.End()
End If
End If
In particular, you aren't showing the code that gets the contents of the message field from the posting and, presumably, assigns those contents to your ContactUs_Body variable.
Since you are uploading an image, you must be using some image uploader code. Either written in VBScript or perhaps an ActiveX component (better).
We probably need to see your code from the point of creation of the uploader object through to where you assign a value to ContactUs_Body.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
The image you mention refers to this Captcha script: "wsp_captcha.asp". That is an external file belonging to a third party and shouldn't account for the difficulty in processing the form.
The rest of the code is as follows. I have a feeling that some CSS is getting in the way of the form being processed, because without it I can't see any errors.
Thanks for your advice (and I hope the code is not too messy for you to read through).
Code:
<%@ Language="VBScript" %>
<% OPTION EXPLICIT %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!--#include file="wsp_captcha.asp" -->
<% Response.Buffer = True %>
<%
'Declaring Variables
Dim smtpserver,youremail,yourpassword,ContactUs_Name,ContactUs_Email
Dim ContactUs_Subject,ContactUs_Body,Action,IsError
' Edit these 3 values accordingly
smtpserver = "smtp.mySite.com"
youremail = "info@mySite.com"
yourpassword = "password"
' Variables from the form post
ContactUs_Name = Request("ContactUs_Name")
ContactUs_Email = Request("ContactUs_Email")
ContactUs_Subject = Request("ContactUs_Subject")
ContactUs_Body = Request("ContactUs_Body")
Action = Request("Action")
' Check email entered is in a valid format........goes here
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Contact us form</title>
<style type="text/css">
html, body {
margin: 0;
background: #fff;
font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;
}
#container {
width: 850px;
margin: 60px 0 60px 0px;
background: #fff;
overflow: auto;
}
<STYLE type="text/css"> label {
font-family: Verdana, Arial, Helvetica, sans-serif;
}
input:focus, textarea:focus { background-color: #8CEED3; }
input {
background-color: #D6F5ED;
border: 1px solid #0C0C4C
}
.submit input {
background-color: #fff;
border: 2px outset #d7b9c9
}
textarea {
background-color: #D6F5ED;
border: 1px solid #0C0C4C
}
.input{
font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;
}
table.myTable { margin-left:60px; }
</style>
</head>
<body>
<%
If Action = "SendEmail" Then
' Check/validate the information entered
If IsValidEmail(ContactUs_Email) = "False" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a valid email address.</font><br>")
End If
If ContactUs_Name = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a name.</font><br>")
End If
If ContactUs_Subject = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a subject.</font><br>")
End If
If ContactUs_Body = "" Then
IsError = "Yes"
Response.Write("<font color=""red"">You did not enter a message.</font><br>")
End If
If WSP_CheckImageCode() <> "OK" Then
Response.Write "<font color=""red"">The image code you have entered is incorrect. Please click the 'Back' button of your browser and type the correct one.</font><br>"
Response.End()
End If
End If
' If no input errors send the email
If Action = "SendEmail" And IsError <> "Yes" Then
Dim strBody
' 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 & "</font>"
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
'SMTP configuration here
'End remote SMTP server configuration section==
ObjSendMail.To = youremail
ObjSendMail.CC = ContactUs_Email
ObjSendMail.Subject = ContactUs_Subject
ObjSendMail.From = ContactUs_Email
' html email..
ObjSendMail.HTMLBody = strBody
'ObjSendMail.TextBody = strBody
ObjSendMail.Send
Set ObjSendMail = Nothing
%>
<font size="2">Your message as seen below has been sent. Thank You !!
<br><br>
<font color="blue">
<% =Replace(ContactUs_Body,vbCr,"<br>") %>
</font>
</font>
<% Else %>
<form action="contact_us.asp" method="POST">
<input type="hidden" name="Action" value="SendEmail">
<div id="container">
<table border="0" cellspacing="1">
<tr>
<td valign="top">
<label for="name">Name:</label>
</td>
<td colspan="2">
<input type="text" class="input" size="35" name="ContactUs_Name" value="<% =ContactUs_Name %>"><br >
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email:</label>
</td>
<td colspan="2">
<input type="text" class="input" size="35" name="ContactUs_Email" value="<% =ContactUs_Email %>"><br >
</td>
</tr>
<tr>
<td valign="top">
<label for="subject">Subject:</label>
</td>
<td colspan="2">
<input type="text" class="input" size="35" name="ContactUs_Subject" value="<% =ContactUs_Subject %>"><br >
</td>
</tr>
<tr>
<td valign="top">
<label for="message">Message:</label>
</td>
<td valign="top">
<textarea name="message" class="input" rows="10" name="ContactUs_Body" cols="35"><% =ContactUs_Body %></textarea><br >
</td>
</tr>
<tr>
<td valign="top">
</td>
<td colspan="2">
<input type="submit" class="submit" value="Send">
<input type="reset" value="Reset">
</td>
</tr>
</table>
<!--end container--></div>
<table class="myTable">
<tr><td><div style="float:left;">
<script type="text/javascript" src="http://webspamprotect.com/captcha/4562/"></script>
<noscript>This form protected by <a href="http://webspamprotect.com" target="_blank" title="Web form spam protection">WebSpamProtect</a>.
JavaScript must be enabled in your browser to view this image.
</noscript>
</div>
</td></tr>
<tr><td>
<div style="float:left";><label>
Please type in the case-sensitive <br>code shown in the image:</label> <input type="text" class="normal" name="wsp_code"/>
</div>
</td></tr></table>
</form>
<% End If %>
</body>
</html>
and this 'formula' (id) is used for all of the form fields in that example, whereas it is not in my form (only in the textarea field which you have kindly pointed out).
I don't need 'id' do I, for each field because the form seems to work as it is? Wouldn't it just be superfluous text if I were to insert 'id' in each of my form fields?
Having a label on a field means that if you click anywhere on the label you are effectively clicking on the form field. In that case of checboxes, radio buttons, and buttons, this means that you get the same effect you get from clicking on the element. This is good because it means the user doesn't have to hit that little tiny radio button on the nose: any place in the label works as well.
In the case of labels on text fields and <textarea>s, I'm not sure I see the point in a <label>. Granted, clicking on the label puts the focus then into the field, but so what?
But many people seem to like to put labels on everything, as here.
Okay...
So there are TWO ways ta attach a label to a field. The simplest (which has some very obscure and minor limitations that really truly aren't work worrying about) is to just surround the field with the label.