Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 25th, 2006, 10:31 AM
Authorized User
 
Join Date: May 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Form Validation not exactly working as intended..

Hey all,

I'm having some problems with some form validation. What I'm trying to do is see if a couple of fields are in the form when the user clicks the submit button. but what's happening is, if there's some errors in the code it's not working as intended. What I'd like to have is it go back to the previous page and just mention that there were a couple errors on the page and for them to go back and change them. Here's the code I'm using for after the user clicks the submit button.

Code:
<%@ Language=VBScript %>
<%  'Written By - JR %>
<%
    Dim Mailer
    Dim iConf
    Dim Flds
    Dim strUserComments

    webaddr=Request.QueryString("pageref")
    'Check for missing fields
    Dim sCheckFailed
    If Request.Form("emto") = "" then sCheckFailed = sCheckFailed & "0FN"
    If Request.Form("emfrom") = "" then sCheckFailed = sCheckFailed & "0LN"
    If Request.Form("emailComments") = "" then sCheckFailed = sCheckFailed & "OLN"

    If sCheckFailed <> "" then 
    Response.Redirect(Request.Form("Page") & "?rem=" & sCheckFailed & "&" & Request.Form)

    'Check for valid email address

        '-- contains a @
    EmailValid3 = false
    For x = 1 to Len(Request.Form("emfrom")) 
        If mid(Request.Form("emfrom"),x,1) = "@" Then
            EmailValid3 = true
        End If
    Next

    '-- contains a .
    EmailValid4 = false
    For x = 1 to Len(Request.Form("emfrom")) 
        If mid(Request.Form("emfrom"),x,1) = "." Then
            EmailValid4 = true
        End If
    Next

    strUserComments = Request.Form("emailComments")

    If Len(strUserComments) > 1 Then
           strUserComments = Replace(strUserComments,Chr(13),"<br>")
    End If 

    If EmailValid3 = False OR EmailValid4 = False Then
        'Response.Redirect(Request.Form("Page") & "?rem=0EM&" & Request.Form)
        Response.Redirect(webaddr)
        SubmitEmail="jreeve@septimatech.com"
    else

    'All is good send the email
 
    Set Mailer = Server.CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields

    Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1

    '**** Path below may need to be changed if it is not correct
    'Flds("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "c:\inetpub\mailroot\pickup"
    'Flds.Update

    Set Mailer.Configuration = iConf

    Mailer.From = Request.Form("emfrom")
    Mailer.to =   Request.Form("emto")
    Mailer.Subject = "Website Email"
    Mailer.HTMLBody = strUserComments & "<br>" & Request.Form("emname") & "<br><br>" & Request.Form("emphone")
    Mailer.Send

    Set mailer = Nothing
    Response.Redirect("thank_you.htm") 
    end if
    %>
So if ya all could help with this that'd be great!!!

Thanks in Advance!

 
Old July 25th, 2006, 03:56 PM
Authorized User
 
Join Date: May 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No worries...hacked my way through a simple form validation...

knew if I actually wrote it out I'd get it heh...

thanks all if you were looking through this.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Javascript validation not working in content page Manoj Bisht ASP.NET 2.0 Basics 0 March 3rd, 2008 02:21 AM
Web Administration Tool intended use rrflore2 ASP.NET 2.0 Professional 0 February 27th, 2007 12:06 AM
Validation not working Ajay Jain General .NET 1 February 26th, 2004 03:07 AM
Form not refreshing after form validation Mimi Javascript How-To 0 August 25th, 2003 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.