SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with client side validation on asp form

    HI all,
    I am new to Asp and was surprised at how hard it was for me to figure out how to create a simple form to send an email (compared to PHP).
    Anyway I have the form working and the tutorial I used to learn it included validation. But it returns error messages after submission and plops them at the top of the page pushing the entire design down.

    I want to either be able to choose where the errors are displayed on the page (Response.Write), or use a simpler JavaScript client side validation before it is submitted.

    The form is just for basic contact info, no passwords or anything funky.

    Any resources, tutorials or help is appreciated

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    client-side validation has nothing to do with ASP- that is javascript world because ASP runs on the server-side.

    have you tried looking at the code ?

    you'll see why the error messages appear where they do.

    Once you know what the code is doing then you can rearrange it to output the result where you want it.

    google :

    forms validation asp -.net

    for additional sources of help/tutorials

  3. #3
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I've looked at the code. Its starts like this:

    <%
    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

    then has some more variables, ends the if statements and goes into the body of the message
    End If

    ' If there were no input errors and the action of the form is "SendEMail" we send the email off
    If Action = "SendEmail" And IsError <> "Yes" Then

    Dim strBody

  4. #4
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well there you have it.

    instead of outputting the error message, capture the error message into a variable

    errmsg = ("<font color=""red"">You did not enter a valid email address.</font><br>")

    concatenate as needed/desired for other messages

    errmsg = errmsg & ".....whatever...."

    then in the preferred location(s)

    response.write(errmsg)

  5. #5
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Attached is a simple form along with javascript to easily validate a form.
    Attached Files Attached Files

  6. #6
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help. I successfully added the error message in the right place, but it appears all of the time. How do I phrase the code so that it only appears if there is an error?
    so right now I added to the error check:
    If IsValidEmail(ContactUs_Email) = "False" Then
    IsError = "Yes"
    errmsg = ("<font color=""red"">You did not enter a valid email address.</font><br>")
    End If

    then under the form field:
    <% Response.Write("<font color=""red"" >You did not enter a valid email address.</font><br>") %>

    Obviously i don't have a full grasp on asp format, so further help is appreciated.

  7. #7
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I then realized that the entire message should ony be in one place, so I instead put:

    response.write(errmsg)

    but get this error:
    Microsoft VBScript runtime error '800a01f4'

    Variable is undefined: 'errmsg'

    Do I need to define errmsg somewhere other than in the validation statement?

  8. #8
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I got it. Added errmsg to the dim variables and it now works.

    Thanks for pointing me in the right direction!

  9. #9
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    close but no cigar. I have got error messages to show up in the right place after submission, but they show up whether there is a error or not.

  10. #10
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    revised! It only shows message if there is an error, but it shows one error on all fields (valid or not) wherever I added response.write(errmsg)

    so i need help in how to define different messages for each field

    Thanks


Tags for this Thread

Bookmarks

Posting Permissions

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