dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Validation Help

  1. #1
    Join Date
    Jun 2007
    Location
    Blue Springs, MO
    Posts
    161

    Question Validation Help

    Ok, so I know this is probably going to be a rather silly question, but as i stated in my last post i am very new at ASP.

    I have taken some tutorials on on validating form input and have half-way succeeded. I have a rather extisive form and want to validate several things, but for the sake of simply learing how to do it right now i am only trying to validate the First Name (fname) portion of my form. I have made it to where it prevents the form from being sent and at the top of the page it prompts the person to fill it in, however it resets the entire form when it does, i would rather have a pop-up warning type prompt that will not reset the form. Is there a way to do this?

    Here is the section of code, i think it will be all you need, i left out the HTML that is below it, and in case this is need-to-know information, the form is on the same page as this validation/mailer:

    <%
    if Request.Form("isSubmitted") = "yes" then

    Dim fname, lname, email, adrs1, adrs2, city, hstate, zip, hphone, wphone, cphone, state, comm, weap, game

    Dim Mail

    Dim Validate_Form

    fname = Trim(Replace(Request.Form("FName"),"""",""""""))
    lname = Trim(Replace(Request.Form("LName"),"""",""""""))
    email = Trim(Replace(Request.Form("Email"),"""",""""""))
    adrs1 = Trim(Replace(Request.Form("Address1"),"""",""""""))
    adrs2 = Request.Form("Address2")
    city = Trim(Replace(Request.Form("City"),"""",""""""))
    hstate = Trim(Replace(Request.Form("HState"),"""",""""""))
    zip = Trim(Replace(Request.Form("Zip"),"""",""""""))
    hphone = Trim(Replace(Request.Form("HomePhone"),"""",""""""))
    wphone = Trim(Replace(Request.Form("WorkPhone"),"""",""""""))
    cphone = Trim(Replace(Request.Form("CellPhone"),"""",""""""))
    state = Trim(Replace(Request.Form("State"),"""",""""""))
    comm = Request.Form("Comments")
    weap = Request.Form("Weapon")
    game = Request.Form("Game")


    Validate_Form=true

    if len(fname)<2 then
    Validate_Form = false
    end if

    if not Validated_Form then

    Response.Write "<p>Please click back on your browser and complete the following fields:</p>"

    if fname<> "" then
    else
    Response.Write "<b> First Name</b><br>"
    end if

    else

    Set Mail = Server.CreateObject("CDONTS.NewMail")

    Mail.From = email

    Mail.To = "cdp103188@gmail.com"

    Mail.Cc = ""

    Mail.Bcc = "cameron@huntingsportsplus.com"

    Mail.Subject = "AWA Request Info Form Submission"

    Mail.Body = "Name: " & fname & " " & lname & vbcrlf & vbcrlf & "Email: " & email & vbcrlf & vbcrlf & "Address: " & vbcrlf & adrs1 & ", " & adrs2 & vbcrlf & city & ", " & hstate & " " & zip & vbcrlf & vbcrlf & "Home Phone: " & hphone & vbcrlf & "Work Phone: " & wphone & vbcrlf & "Cell Phone: " & cphone & vbcrlf & vbcrlf & "State: " & state & vbcrlf & vbcrlf & "Weapon Preferance: " & weap & vbcrlf & vbcrlf & "Game Preferance: " & game & vbcrlf & vbcrlf & "Comments: " & vbcrlf & comm

    Mail.BodyFormat = 1

    Mail.MailFormat = 1

    Mail.Send


    end if

    end if

    %>

    Thank You,
    Cameron

  2. #2
    Join Date
    Jun 2007
    Location
    Blue Springs, MO
    Posts
    161
    I actually have an updated version of that, this one validates several variables but still refreshes the page and resets the form when it does so, anyway, here is the code that i need modified. I would like to keep the same type format however, i want for it to list the things that were imporperly filled out, mabey it is possible to generate a html page pop-up?

    <%
    if Request.Form("isSubmitted") = "yes" then

    Dim fname, lname, email, adrs1, adrs2, city, hstate, zip, hphone, wphone, cphone, state, comm, weap, game

    Dim Mail

    Dim Validate_Form, fnameCheck, lnameCheck, emailCheck, adrs1Check, cityCheck, stateCheck, zipCheck, ph1Check, ph2Check, ph3Check

    fname = Trim(Replace(Request.Form("FName"),"""",""""""))
    lname = Trim(Replace(Request.Form("LName"),"""",""""""))
    email = Trim(Replace(Request.Form("Email"),"""",""""""))
    adrs1 = Trim(Replace(Request.Form("Address1"),"""",""""""))
    adrs2 = Request.Form("Address2")
    city = Trim(Replace(Request.Form("City"),"""",""""""))
    hstate = Trim(Replace(Request.Form("HState"),"""",""""""))
    zip = Trim(Replace(Request.Form("Zip"),"""",""""""))
    hphone = Trim(Replace(Request.Form("HomePhone"),"""",""""""))
    wphone = Trim(Replace(Request.Form("WorkPhone"),"""",""""""))
    cphone = Trim(Replace(Request.Form("CellPhone"),"""",""""""))
    state = Trim(Replace(Request.Form("State"),"""",""""""))
    comm = Request.Form("Comments")
    weap = Request.Form("Weapon")
    game = Request.Form("Game")


    Validate_Form=true
    fnameCheck=true
    lnameCheck=true
    emailCheck=true
    adrs1Check=true
    cityCheck=true
    stateCheck=true
    zipCheck=true
    phoneCheck=true

    if len(fname)<1 then
    Validate_Form = false
    fnameCheck = false
    end if

    if len(lname)<1 then
    Validate_Form = false
    lnameCheck = false
    end if

    if len(email)<1 or InStr(email,"@")=0 then
    Validate_Form = false
    emailCheck = false
    end if

    if len(adrs1)<1 then
    Validate_Form = false
    adrs1Check = false
    end if

    if len(city)<1 then
    Validate_Form = false
    cityCheck = false
    end if

    if len(hstate)<1 then
    Validate_Form = false
    stateCheck = false
    end if

    if len(zip)<1 then
    Validate_Form = false
    zipCheck = false
    end if

    if len(hphone)<1 and len(wphone)<1 and len(cphone)<1 then
    Validate_Form = false
    phoneCheck = false
    end if

    if not Validate_Form then

    Response.Write "<p>Please complete the following fields:</p>"

    if not fnameCheck then
    Response.Write "<b> First Name</b><br>"
    end if

    if not lnameCheck then
    Response.Write "<b> Last Name</b><br>"
    end if

    if not emailCheck then
    Response.Write "<b> Email Address</b><br>"
    end if

    if not adrs1Check then
    Response.Write "<b> Street Address</b><br>"
    end if

    if not cityCheck then
    Response.Write "<b> City</b><br>"
    end if

    if not stateCheck then
    Response.Write "<b> State</b><br>"
    end if

    if not zipCheck then
    Response.Write "<b> Zipcode</b><br>"
    end if

    if not phoneCheck then
    Response.Write "<b> At least one valid Phone Number</b><br>"
    end if

    else

    Set Mail = Server.CreateObject("CDONTS.NewMail")

    Mail.From = email

    Mail.To = "cdp103188@gmail.com"

    Mail.Cc = ""

    Mail.Bcc = "cameron@huntingsportsplus.com"

    Mail.Subject = "AWA Request Info Form Submission"

    Mail.Body = "Name: " & fname & " " & lname & vbcrlf & vbcrlf & "Email: " & email & vbcrlf & vbcrlf & "Address: " & vbcrlf & adrs1 & ", " & adrs2 & vbcrlf & city & ", " & hstate & " " & zip & vbcrlf & vbcrlf & "Home Phone: " & hphone & vbcrlf & "Work Phone: " & wphone & vbcrlf & "Cell Phone: " & cphone & vbcrlf & vbcrlf & "State: " & state & vbcrlf & vbcrlf & "Weapon Preferance: " & weap & vbcrlf & vbcrlf & "Game Preferance: " & game & vbcrlf & vbcrlf & "Comments: " & vbcrlf & comm

    Mail.BodyFormat = 1

    Mail.MailFormat = 1

    Mail.Send


    end if

    end if

    %>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles