Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Iterating through a Form

Status
Not open for further replies.

arundahar

Programmer
Apr 27, 2001
53
GB
Hi, i have a large registration page which has about 23 fields on it for the User to fill in. 20 are mandatory the rest optional. Most are TEXT, some are SELECT, some are CHECKBOXES. How can i check each of these form elements (using ASP only!) without writing out:

If Len(strUsername) = 0 Then
blah
End If

If Len(strpassword) = 0 Then
blah
End IF

If strPassword <> strVerifyPassword Then

blah
End If

..and so on...

I've used the For each item in Request.Form, but this returns the field in a very bizarre order and doesn't seem to handle the checkboxes. The registration page is submitted to a handler page, so if the user enters anything incorrectly i want to redirect them to the original page with the incorrect fields highlighted in red (i'll do this by re-directing and using the querystring - any other ways of doing this?)

Thanks

Arun
 
Well one way that you could check your fields is to make a generic sub.

Sub checkAll(fieldName)
if len(fieldName)= 0 then
blah
end if
end sub

then call it for each use.

call checkAll(strUsername)
This way you pass the field name to the sub for it to check.
As for sending it back you could put all the fields that fail into a session variable seperated by a comma or space or something then run a sub on your form page to parse out the field names and highlight them in red.

I hope that helps.

Roj
 
thanks for the help. I can't use Session Variables however, any other way of doing this?

Either way it looks like i'm going to have to do loads of If statements and return the errors through the Querystring.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top