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 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    50
    Thanks
    31
    Thanked 1 Time in 1 Post

    Make Email Field of Form Required

    How would I make the Email field of a form Required?

    http://jaxpubliclibrary.org/lib/askform.html
    http://jaxpubliclibrary.org/lib/askformhandler.asp

    Code:
    <div id="askalibrarian">
    <form action="askformhandler.asp" method="post" name="ReferenceQuestion" id="ReferenceQuestion" >
    <input type="hidden" name="department" value="askalibrarian" />
    				
    <h1><span>Ask a Librarian: Email Reference Service</span></h1>									
    <div class="webform">		
    						<label>Name:</label>
    <div class="left"><input type="text"     class="blue_form_box"name="SubmittedBy" maxlength="100" size="50" />
    <br /><span class="redspec">* (Required)</span></div>
    						
    <p style="clear:both"></p>
    						
    <label>E-Mail:</label>
    <div class="left"><input type="text" class="blue_form_box"name="Email" maxlength="100" size="50" </div>
    						
    <p style="clear:both"></p>
                        
    <label>Zip Code:</label>
    <div class="left"><input type="text" class="blue_form_box"name="Zip" maxlength="100" size="50" /></div>
    						
    <p style="clear:both"></p>
                        
    <label>Local Phone:</label>
    <div class="left"><input type="text" class="blue_form_box"name="Phone" maxlength="100" size="50" /></div>
    						
    <p style="clear:both"></p>                   
    						
    <label>Use Category:</label>
    <div class="left">
    <input  type="radio" name="scope" value="pre-K" />Pre-K 
    <input type="radio" name="scope" value="K-5" />K-5th Grade 
    <input type="radio" name="scope" value="6-8" />Middle School 
    <input type="radio" name="scope" value="9-12" />High School
    <input type="radio" name="scope" value="College" />College
    <input type="radio" name="scope" value="General" />General Public
    <input type="radio" name="scope" value="Business" />Business	</div>
    <p style="clear:both"></p>
    						
    <label>Question:</label>
    <div class="left"><textarea class="blue_form_box" name="CustomerQuery" rows="5" cols="50"></textarea></div>			
    <p style="clear:both"></p>
    						
    <div align="center">
    <input type="submit" value="Submit Question" />                        
    <input type="reset" value="Erase Typing" /> 
    	</div>
    	</div>
    	</form>
    	</div>

    Code:
    <h1><span>Contact Jacksonville Public Library</span></h1>
    			
    <p>Thank you!</p>
    
    <div class="webform">		
    			
    <%
    Dim MsgBody, TargetEmail, TargetPhone, TargetSubject
        
    TargetDept = "Reference"
    TargetEmail = "inform@coj.net"
    TargetSubject = "Reference Question"
    MsgBody = "The following question was received from " & Request.Form("SubmittedBy") 
    MsgBody = MsgBody & vbCRLF  & vbCRLF 
    MsgBody = MsgBody & "Submitted by: " & Request.Form("SubmittedBy") & vbCRLF 
    MsgBody = MsgBody & "Email address: " & Request.Form("Email") & vbCRLF
    MsgBody = MsgBody & "Zip code: " & Request.Form("Zip") & vbCRLF
    MsgBody = MsgBody & "Local Phone: " & Request.Form("Phone") & vbCRLF
    MsgBody = MsgBody & "Use Category: " & Request.Form("scope") & vbCRLF  & vbCRLF 
    MsgBody = MsgBody & "Customer Query: " & Request.Form("CustomerQuery") 
    %>
    
    <p><strong>Recap of submission:</strong></p>
    <p><strong>Subject:</strong></p> <% Response.Write(TargetSubject) %> 
    <p><strong>Department:</strong></p> <% Response.Write(TargetDept) %> 
    <p><strong>Your Message:</strong></p> <% Response.Write(MsgBody) %>
    
    <%
    Set objEmail = CreateObject("CDO.Message")
    	objEmail.From = "website@jpl.coj.net"
    	objEmail.To = TargetEmail
    	objEmail.Subject = TargetSubject
    	objEmail.Textbody = MsgBody
    	objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    	objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
            "smtp.coj.net" 
    	objEmail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    	objEmail.Configuration.Fields.Update
    	objEmail.Send	
    %>		
    
    <p class="clear_both"></p>
    Thank you for any help you can give me.
    Last edited by ShaneC; 11-16-2011 at 06:40 AM. Reason: Added code tags

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    You should probably do *BOTH* JavaScript validation in the HTML page *AND* ASP validation, just in case the user has JavaScript turned off.

    And I would validate the entire <form>, not just the email address.
    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:

    Elbee (11-15-2011)

  • #3
    New Coder
    Join Date
    Oct 2010
    Posts
    50
    Thanks
    31
    Thanked 1 Time in 1 Post
    Hey,

    I posted this in the <head>
    Code:
    <script>
    
    function validateForm()
    {
    var x=document.forms["ReferenceQuestion"]["email"].value;
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
      {
      alert("Not a valid e-mail address");
      return false;
      }
    }
    </script>
    and input this
    Code:
    <form action="askformhandlertest.asp" method="post" name="ReferenceQuestion" id="ReferenceQuestion" onsubmit="return validateForm()" >
    It still doesn't work. There must be something about the http://jpl.coj/net/lib/askformhandler.asp file that prevents it from working.

    You know how inexperienced I am! I'm a darned Librarian. Please help Oh Great One!
    Last edited by ShaneC; 11-16-2011 at 06:41 AM. Reason: Added code tags

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    So do you want to forget about the Javascript and do it all with ASP? No point in doing it twice for something like this, I wouldn't think.
    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.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Here. Try this. Requires NO modifications to your handler page. But now the "askform.html" is replaced by this page, which you can name "askform.asp".

    Code:
    <html>
    <head>
    <title>Ask a Librarian: Email Reference Service</title>
    
    <style type="text/css">
    label { font-size: normal; }
    label span { color: blue; }
    
    label.required {
        color: red;
        font-size: large;
    }
    label.required span {
        color: red;
        font-size: large;
        font-weight: bold;
    }
    </style>
    </head>
    <body>
    <%
    scope = ""
    
    If Trim(Request("department")) = "askalibrarian" Then
        ' only do this if the form was posted back to here:
        SubmittedBy = Trim(Request("SubmittedBy"))
        Email = Trim(Request("Email"))
        scope = Trim(Request("scope"))
        CustomerQuery = Trim(Request("CustomerQuery"))
        okay = true
    
        If Len(SubmittedBy) < 5 Then nameLabel="class=""required"" " : okay = False
        If scope = "" Then scopeLabel="class=""required"" " : okay = False
        If Len(CustomerQuery) < 15 Then custLabel="class=""required"" " : okay = False
    
        Set emre = New RegExp
        emre.Pattern = "^([a-z][\w\-\']*\.)*[a-z][\w\-\']*\@([a-z][\w\-\']*\.)+[a-z]{2,6}$"
        emre.IgnoreCase = True
    
        If Not emre.Test(Email) Then emailLabel="class=""required"" ": okay = false
    
        If okay Then Server.Transfer "askformhandler.asp"
    End If
    %>
    <form action="" method="post" id="ReferenceQuestion" >
    <div id="askalibrarian">
        <input type="hidden" name="department" value="askalibrarian" />
    
        <h1><span>Ask a Librarian: Email Reference Service</span></h1>
    
    <% If Not okay Then %>
        <h2 style="color: red;">
            One or more required fields are not correctly entered, as indicated below.
        </h2><br/>
    <% End If %>
    
        <div class="webform">
            <label <%=nameLabel%>>Name: <span>* (Required)</span></label>
            <div class="left">
                <input class="blue_form_box" name="SubmittedBy" value="<%=SubmittedBy%>" maxlength="100" size="50" />
            </div>
            <p style="clear:both"></p>
            <label <%=emailLabel%>>E-Mail: <span>* (Required)</span></label>
            <div class="left">
                <input class="blue_form_box" name="Email" value="<%=Email%>" maxlength="100" size="50" />
            </div>
            <p style="clear:both"></p>
    
            <label>Zip Code:</label>
            <div class="left">
                <input class="blue_form_box"name="Zip" value="<%=Zip%>" size="50" />
            </div>
            <p style="clear:both"></p>
    
            <label>Local Phone:</label>
            <div class="left">
                <input class="blue_form_box"name="Phone" value="<%=Phone%>" size="50" />
            </div>
            <p style="clear:both"></p>
    
            <label <%=scopeLabel%>>Use Category: <span>* (Required)</span></label>
            <div class="left">
    <%
    rbs = Array("Pre-K::Preschool to Kindergarten","K-5::K-5th Grade","6-8::Middle School", _
                "College::College","General::General Public","Business::Business")
    For r = 0 To UBound(rbs)
        rb = Split(rbs(r),"::")
        If rb(0) = scope Then chk=" checked " Else chk = ""
    %>
                <label><input type="radio" name="scope" value="<%=rb(0)%>" <%=chk%> /><%=rb(1)%></label>
    <%
    Next
    %>
            </div>
            <p style="clear:both"></p>
    
            <label <%=custLabel%>>Question: <span>* (Required)</span></label>
            <div class="left">
                <textarea class="blue_form_box" name="CustomerQuery" r
                    ows="5" cols="50"><%=CustomerQuery%></textarea>
            </div>
            <p style="clear:both"></p>
    
            <div align="center">
            <input type="submit" value="Submit Question" />
            <input type="button" value="Clear Typing" onclick="location.href='askform.asp';"/>
            </div>
        </div><!-- end of webform -->
    </div><!-- end of asklibrarian -->
    </form>
    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:

    Elbee (11-22-2011)


  •  

    Posting Permissions

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