How to verify a database form?

They have: 12 posts

Joined: Mar 2000

Hi,

I did a database form in asp and I would like to know, the best way to verify that all the fields were filled and also check if the information is ok.

What is the best way to do that?

If someone could send the code.

Thank you for your collaboration.

Best Regards,

Simon Baillargeon

Simon Baillargeon

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Simon,

As far as validation goes, I always like to do both client side and server side validation. So when the user clicks the submit button on the form you would have some sort of JavaScript or VBScript function that checks the fields you want checked and either halt submission or let it continue based on the results.

When you're form handler ASP is called into action you basically do the same thing you did client side. So something like:

'Check for blank
If Request.Form("FieldName") = "" Then
Response.Redirect "form.asp"
Session("ErrorMessage") = "Please fill in Field Name"
End If

When doing this it's a good idea to store all the field values in sessions, that way the user doesn't have to fill out the form again when they are redirected to it.

As far as giving you code examples, there's lots of examples of form validation kicking around. Just remember to do all your checking and validation before you open your database connection or start saving values to it.

Regards,
Peter J. Boettcher

[This message has been edited by Peter J. Boettcher (edited 13 March 2000).]

PJ | Are we there yet?
pjboettcher.com

They have: 2,390 posts

Joined: Nov 1998

Do you write javascript as well Pete?
JP

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

JP,

I like to stick to VBScript server side since I find it simpler to write, but all my client side scripting is JavaScript since Netscape doesn't like VBScript. I've been using both scripting languages for almost three years but since I had VB experience using VBScript was almost a no brainer.

I guess the same code in JavaScript would be something like this:

'Check for blank
If (Request.Form("FieldName") == "")
{
Session("ErrorMessage") = "Please fill in Field Name"
Response.Redirect "form.asp"
}

Regards,
Peter J. Boettcher

PJ | Are we there yet?
pjboettcher.com

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Simon,

As Peter said there are loads of validation scripts around. One of them is the "Form Validation 1" javascript script at my site. It's sort of a template (with explanation), checking all types of input elements (text, select lists, checkboxes, etc) for user non-action.
It doesn't submit if there are any errors. You will need to modify for your specific form elements and error messages, but it's a start.
Hope this helps

Vinny

------------------
GrassBlade: cut&paste javascript

Where the world once stood
the blades of grass cut me still

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.