| One
of the problems with doing error checking the way it
was demonstrated in part one is when the user is redirected
back to the input page do to an error all their inputted
information is gone. This can be frustrating to the
user if they just type in a lot of information and because
they forgot one item they have to retype it all over
again.
There is many different solution to fix this problem.
One is to only use one web page not two. In part one
you built an input page that passes all the information
to a process page to do the error checking. You can
combine both these pages into one. When the user enters
in their data and clicks on the submit button all the
information is pass to itself, not another page. In
short it calls itself. You will have all your error
checking code at the top of the web page to process
the data. If it passes the error checking your code
will redirect the user to the next page. Else if there
is an error, you are already on the original page thus
you just have to display an error message and display
the page with their data again.
There is many little tips in order to do error checking
these way. This demo will show you them.
The first one is how do you get the page only to run
the error checking when the page calls itself. If you
just copy your error checking from part one and paste
it at the top of the page it will run every time you
try to display the page. What will happen is the first
time the page is loaded the page will have no data thus
the error checking will think it is missing required
information. The page will display your error message.
You have to get the page only to run the code when it
calls itself. To do this you will need a way do determine
when to run the code and when not too. The easiest way
to do this is by using a hidden HTML input tag on your
page.
Example:
<INPUT
type="hidden" name="action" value="check">
What will happen is when the page calls itself there
will be a variable called action
with the value check in
existents. If the page doesn't call itself, [Example:
first time it loads] there will be no variable called
action in existents. For
all you have to do is wrap all your error checking code
inside of a if statement that only runs if the variable
exist.
Example:
Dim
strAction
strAction = request.form("action")
if LCase(strAction) =
"check" then
Do
your error checking
end if
|