• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

VB Script - Form Validation Routine

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
EWilson12
Asked:
EWilson12
  • 6
  • 5
  • 2
2 Solutions
 
WebsiteNationCommented:
Check the following:

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

Steve
0
 
EWilson12Author Commented:
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
 
EsopoCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
WebsiteNationCommented:
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
 
WebsiteNationCommented:
Opps, Correction:

<% If Len(Request.Form("field")) = 0 Then Response.Write("Error") End If %>
0
 
EWilson12Author Commented:
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
 
WebsiteNationCommented:
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
 
EWilson12Author Commented:
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
 
WebsiteNationCommented:
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
 
EWilson12Author Commented:
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
 
EsopoCommented:
Gald to help :)

Just one last suggestion:
Would you please turn those nasty & disturbing table borders off?
0
 
EWilson12Author Commented:
lol

I'll consider it.
0
 
WebsiteNationCommented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now