Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    Message field not working

    Hello

    I have a Web form and although I have completed all form fields as part of a test, I get the error:
    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:

    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
    And the following in my form:

    Code:
    <div id="container"> 
        <table border="0" cellspacing="1">
    		<tr>
    			<td valign="top">
                            <label for="name">Name:</label>
    				
    			</td>
    			<td colspan="2">
    				<input type="text" id="name" 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" id="email" 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" id="subject" 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" id="message" class="textarea" rows="10" name="ContactUs_Body" cols="35"><% =ContactUs_Body %></textarea><br >
    			</td>
    		</tr>
    		<tr>
    			<td valign="top">
    				&nbsp;
    			</td>
    			<td colspan="2">
    
    			<input type="submit" value="Send">
                            <input type="reset" value="Reset">
          
            
           			</td>
    		</tr>
    	</table>
        <!--end container--></div>
    Thanks for any suggestions

    Steve

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    You aren't showing enough code.

    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.

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Old Pedant

    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">
    				&nbsp;
    			</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>

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Look:
    Code:
    <textarea name="message" class="input" rows="10" name="ContactUs_Body" cols="35"><% =ContactUs_Body %></textarea><br >
    Only the first name is used, so if you want the contents of the field, as written, you would need to use Request("message")

    Or get rid of the extra name=

    I guess I should have seen that in first post, but as soon as I saw name="message" I quite looking.
    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.

  • Users who have thanked Old Pedant for this post:

    SteveH (05-03-2012)

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Old Pedant

    Yes, this works:

    Code:
    <textarea "message" class="input" rows="10" name="ContactUs_Body" cols="35"><% =ContactUs_Body %></textarea><br >
    without 'name' (I didn't want to mess up the name in name="ContactUs_Body"

    Thanks again for your patient help.

    Steve

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    It's also illegal HTML.

    There is no valid HTML that would allow the bare "message" in that tag.

    Clearly, looking at the other fields, you INTENT was for that to be an ID, for use by the <label>.

    So it should be
    Code:
    <textarea id="message" class="input" rows="10" name="ContactUs_Body" cols="35"
        ><% =ContactUs_Body %></textarea><br >
    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.

  • #7
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Thanks Old Pedant

    Looking at this page: http://pastebin.com/NjBtnQiz I see that they have (for example):

    Code:
    <label for="email">Email Address (required)</label> 
    
                  <input id="email" name="email" class="text" />
    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?

    Cheers

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,965
    Thanks
    79
    Thanked 4,429 Times in 4,394 Posts
    Yes and no.

    You are using <label>s.

    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.

    Example:
    Code:
    <label><input type="checkbox" name="gender" value="M"/> Male</label>
    So clicking anywhere on "Male" will check the box.

    The other way is the way used on your page: Match up the for= attribute of the <label> with the id= attribute of the form element:
    Code:
    <label for="email">Email Address (required)</label> 
    <input id="email" name="zambonisl" class="text" />
    Notice that the for= does not care what the name= for the field is.

    SO...

    You choose. If you use id="message" than indeed your label specified as
    Code:
    <label for="message">Message:</label>
    will work as described above.

    If you omit the ID, then the label has no purpose other than a descriptive message.
    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.

  • Users who have thanked Old Pedant for this post:

    SteveH (05-04-2012)

  • #9
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Thanks again Old Pedant for your careful explanation: basically, use ID when it has a purpose.

    Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •