Solved

VB Script - Form Validation Routine

Posted on 2004-09-28
13
234 Views
Last Modified: 2012-05-05
Does anyone have a decent generic form validation script they want to share?  I am looking for a script I can call for each field in my form where I can specify a validation type (Phone, Email, URL, generic text, etc) and set a required/not required flag on a field by field basis.  Please include the script and the code to call it.

Thanks a ton, E
0
Comment
Question by:EWilson12
  • 6
  • 5
  • 2
13 Comments
 
LVL 1

Expert Comment

by:WebsiteNation
ID: 12174696
Check the following:

Javascript Solution: http://www.yaromat.com/dw/?ex=Check%20Form%20MX

Steve
0
 
LVL 1

Author Comment

by:EWilson12
ID: 12174777
wee free plugins, nice plugin but unfortunately I am hesitant to use pop ups (win XP SP2 and all) to notify the user that the form is incorrect.  I would rather repop the form page with labels for all incorrect fields in a BOLD RED font with a short description message at the top of the page informing the user to check all the fields that are marked in this manner for errors.  I did however install the plugin for future use so 50pts for your assist once this question is answered.
0
 
LVL 14

Assisted Solution

by:Esopo
Esopo earned 100 total points
ID: 12175122
Quoting myself from a different Q:

You need to decide wether you want this validation done on the server or client side. (or both)

On the client side you can have the validation pop a message before sending the form. On the server you have more control and reliability but the user must wait until the new page loads telling they missed a spot.

For client side validation you'll be using probably javascript, with something like what Steve suggested. For server side validation you need your host server to have some form of cgi scripting like ASP or PHP.


This is a good link for understanding the main reasons for using Server Side valdiation:
http://www.asptechniques.com/content.asp?a=co&cID=949



Here you can find great ASP scripts for many types of validations:
http://www.aspin.com/home/tutorial/formproc/validati


Best regards,

Esopo.
0
 
LVL 1

Expert Comment

by:WebsiteNation
ID: 12176112
I agree. Then use ASP validation. It will be better for you.

Ex

<% If Len Request.Form("field") = 0 Then Response.Write("Error") End If %>
0
 
LVL 1

Expert Comment

by:WebsiteNation
ID: 12176114
Opps, Correction:

<% If Len(Request.Form("field")) = 0 Then Response.Write("Error") End If %>
0
 
LVL 1

Author Comment

by:EWilson12
ID: 12181702
Wouldn't a combination of both be the best?  1st Validate on the page itself so the user has immediate feedback w/o having to reload the page, then validate with an asp page for additional control and reliability?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Expert Comment

by:WebsiteNation
ID: 12181843
Yes, I use both methods. It is really up to you. I use the javascriopt mehtods for non-critcal stuff. If I need a gauranteed validation I will use ASP. Once you start writing your own ASP validation, you will get the hang of it. I like it much better then javascript which can get very messy at times. :)

A good place to learn about VBScript and ASP is here: http://www.w3schools.com/
0
 
LVL 1

Author Comment

by:EWilson12
ID: 12182011
wouldn't a response.write fire before a user even gets to the field, when the page is initially loaded? Can I use an in the page script that gets called when the forms submit button is pressed?  If I can do it that way can someone show me how to modify the following code to call the on page script instead of submitting the form?

<form name="form1" method="post" action="applied.asp">
      <input type="text" name="textfield">
      <input type="submit" name="Submit" value="Submit">
</form>

Also, If I do call a script can someone show me an example of posting the form data to the next page from within the script seeing how my submit button won't do this for me once modified to call the script.

I am thinking of including some error text in my page that initially is the same color as the background then if the validation rules are not met the script will just change the text color and refresh the page.
0
 
LVL 1

Accepted Solution

by:
WebsiteNation earned 400 total points
ID: 12182091
You have 2 options. You can either submit the form to itself:
(Assuming Submit button is labeled Submit)
<% If Request.Form("Submit") = "Submit" Then
    If  error testing code...
    Process error messages...
    Else
    Send Form Script
    End If
End If %>

Or submit the form to a confirmation page that will test for the errors.
0
 
LVL 1

Author Comment

by:EWilson12
ID: 12383589
Sorry for the delay but it took me awhile to get on track, My final result was no client side validation at all and I ended up doing exactly what Websitenation suggested by having the form call itself, actually I ended up with 3 pages for the application:

index_apply.htm was just used to collect the data and submit it to index_apply.asp
index_apply.asp was used for validation and data correctio and either calls itself until validation is passed
index_applied.ap is called when all validation has been met and contains the CDONTS for emailing the application.

final result was:

http://www.usamca.com/index_apply.htm

actually ran accross something new (thanks to BubbaisBest for his input on another question i had) for me to get the form data over to my applied page w/o the use of a form action and that was:

Server.Execute("index_applied.asp")

worked really well.

Thanks for all the info, E
0
 
LVL 14

Expert Comment

by:Esopo
ID: 12383661
Gald to help :)

Just one last suggestion:
Would you please turn those nasty & disturbing table borders off?
0
 
LVL 1

Author Comment

by:EWilson12
ID: 12383794
lol

I'll consider it.
0
 
LVL 1

Expert Comment

by:WebsiteNation
ID: 12384437
Great, glad that worked! True, you don't need javascript if you submit the form to itself and use ASP. But, sometimes I will use both. I like that Javascript gives an immediate message and saves a trip to the server. But, I will also backup the form with an ASP validation for anything that MUST be submitted. This is more important for database applications.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now