How to handle invalid entries in form submission

D

Danny

Does anybody have a nice method of forcing a user to enter a value into a
form using asp?
I think the best is to have a popup when they hit submit that will stay on
the same page and then just alert the user to enter something in so and so
text box.

Thanks in advance
 
C

CJM

You have three basic approaches for data validation:

1) Client-side: Use javascript to check the form data before it is posted.
2) Server-side: Use ASP to check the posted data and react accordingly
3) Use both - which is, needless to say, the recommended route IMHO

The scenario you talk about comes under category 1), and and would use
Javascript. In my case, this is usually not a problem since most of my work
is intranet based, so I know about my clients. If your project is on the
internet, you should proceed with caution - 13% of users do not have
javascript or have it disabled. If you are prepared to risk this, or if this
is not an issue, I can send you a client-side validation scipt that I use -
you can modify to fit your needs.

Clearly you could just opt for a server-side validation solution; the
disadvantage is that it requires a few more trips across the lines, and it
is slightly different to code, but it would work for all clients. If you
want to be as inclusive and thorough as possible you should choose this
option.

In most of my apps, I use client-side validation to check that numeric
fields are indeed numeric, mandatory fields or filled in, listboxes have
selected items etc... When the forms are submitted, I do further checks,
including checks for SQL injection. The client-side validation checks the
basics, and the server-side validations looks into the detail.

I realise that this is quite a 'shotgun response' to your question, but I'm
trying look at a broader scope. Yes, you can achieve what you asked using
javascript, but whether you should is up to you.

Chris

http://www.brightnorth.com/snippets/
'validation master' is the full readable version, 'validation.js' is the
crunched version (half the size)
 
D

David C. Holley

I originally went with client-side myself, and then converted to
server-side since the page that I was sending to my visitors ended up
being incredibly HUGE. My thinking is that I'd prefer another round-trip
to the server as oppposed to having the visitor wait for the page to
load. It also allowed me to hide some validation that I'd prefer to keep
private.

David H.

http://www.gatewayorlando.com/content/reservationRequestV3_submit.asp
 
C

CJM

David C. Holley said:
I originally went with client-side myself, and then converted to
server-side since the page that I was sending to my visitors ended up
being incredibly HUGE.

This is a fair point, which is particularly relevant to one-off pages or to
complex validation routines. In my pages, I'm using the same js script again
& again - the first time you call a validated page you have an extra 6k to
download (not a huge amount!). Any subsequent page that uses the same
validation routines uses the cached version, which obviously has no
bandwidth overhead.
My thinking is that I'd prefer another round-trip
to the server as oppposed to having the visitor wait for the page to
load.

Unless your validation routine is THAT big, the client-side method will
usually still be the quicker.
It also allowed me to hide some validation that I'd prefer to keep
private.

Which is probably one of the best reasons you could give. Fair point.

CJM
 
D

Danny

Danny said:
Does anybody have a nice method of forcing a user to enter a value into a
form using asp?
I think the best is to have a popup when they hit submit that will stay on
the same page and then just alert the user to enter something in so and so
text box.

Thanks in advance

Thanks for both of your responses.
and thank you CJM for hte code. I look forward to experimenting.

David, i like the server side method as well.
But how do you handle this.
Do you give them back the same form with a message at the top? IF so, how
do you ensure the form still has the user data so they don't have to type it
all in again, also, do you call the same .asp page?

Thanks in advance
Danny
 
D

David Holley

I handle the validation with three sub-scripts that are included into
the *.asp page that the first form submits to.

reservationRequestV3_Validation.asp
reservationRequestV3_Processing.asp
reservationRequestV3_InvalidCenter.asp

_Validation.asp obviously handles the validation. I approached the
validation by writing functions to validate the various TYPES of fields
(i.e. all text, phone number, select list, etc.) Then I use an variable
to capture the error returned by the function for the particular field
and if neccessary any applicable text message. The variables are named
(userNameValidationError, responseMethodValidationError,
userPhoneHomeValidationError, userPhoneHomeValidationText, etc.)

If all of the _validationError variables = 0, _Processing is executed to
process the request. '0' assumes that no error occurred.

If one or more of the _validationError variables <> 0, the
_InvalidCenter script executes. This script sends a new form to the
visitor indicating which fields are valid and which are not. If a
particular value is valid, a HIDDEN input is written with the value set
to <%resposne.write request("fieldName")%> to maintain the original
value. The value is then written as text to display it for reference. If
the value is invalid, a form field is written.

if nameValidationError = 0 then
'write a hidden form field with the value set to the NAME
'write the actual value as text so the user can see it
else
'write a form field with the value and highlight the field
'write an error message explaining the problem
end if

The INVALID FORM submits to _Validation.asp to allow the process to
execute again if needed.

I choose to split up the three scripts to make life easier in making
changes and debuggin since if all three were combined the total number
of lines would be horendeous(sp).

David H.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top