Richard Mueller... you out there?

J

Jim D

Hi Richard. You've helped me out in the past so I thought I'd present you
with the latest problem that we can't seem to fix.

Consider an ASP page with a form that has a few text fields... name,
address, comments etc. The page posts to itself so we have the usual line
that says:

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then

If the users input passes various validations we write it to a database and
display a thank you message below the form. The problem is when a validation
fails. When that happens we display a sorry, try again kind of message, but
the problem is that the page refreshes and the users data that they typed in
is cleared form the text boxes. We want the data to persist until the form
is successfully submitted, then it can clear (because this is what a user
expects when the form is submitted. If the data persisted after success,
they would get confused and probably resubmit it)

We've tried different functions in conjunction with setting the default
value of the text boxes to:
<%= Request.Form("textboxname") %>, but the best we can get is for the data
to persist, regardless of whether the submission is good or not.

Is there anything clever you can come up with? If I have to I can put an
example on the web.

Thank you!
 
A

Anthony Jones

Jim D said:
Hi Richard. You've helped me out in the past so I thought I'd present you
with the latest problem that we can't seem to fix.

Consider an ASP page with a form that has a few text fields... name,
address, comments etc. The page posts to itself so we have the usual line
that says:

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then

If the users input passes various validations we write it to a database and
display a thank you message below the form. The problem is when a validation
fails. When that happens we display a sorry, try again kind of message, but
the problem is that the page refreshes and the users data that they typed in
is cleared form the text boxes. We want the data to persist until the form
is successfully submitted, then it can clear (because this is what a user
expects when the form is submitted. If the data persisted after success,
they would get confused and probably resubmit it)

We've tried different functions in conjunction with setting the default
value of the text boxes to:
<%= Request.Form("textboxname") %>, but the best we can get is for the data
to persist, regardless of whether the submission is good or not.

Is there anything clever you can come up with? If I have to I can put an
example on the web.

Thank you!

This works:-

<%

Dim mbFailed : mbFailed = True

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
mbFailed = LCase(Request.Form("field1")) <> "bad"
End If

%>
<html>
<body>
<form method="POST" action="test.asp">
<input name="field1" value="<%=GetDefault("field1")%>" />
<input type="submit" value="Post" />
</body>
</html>
<%
Function GetDefault(Name)
If Not mbFailed Then
GetDefault = Server.HTMLEncode(Request.Form(Name))
End If
End Function
%>

It's same as the other one I posted only it uses the more tranditional
REQUEST_METHOD instead of HTTP_METHOD which are actually the same thing. ;)
 
S

SLH

got it working. thanks everyone

Anthony Jones said:
This works:-

<%

Dim mbFailed : mbFailed = True

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
mbFailed = LCase(Request.Form("field1")) <> "bad"
End If

%>
<html>
<body>
<form method="POST" action="test.asp">
<input name="field1" value="<%=GetDefault("field1")%>" />
<input type="submit" value="Post" />
</body>
</html>
<%
Function GetDefault(Name)
If Not mbFailed Then
GetDefault = Server.HTMLEncode(Request.Form(Name))
End If
End Function
%>

It's same as the other one I posted only it uses the more tranditional
REQUEST_METHOD instead of HTTP_METHOD which are actually the same thing.
;)
 

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,019
Latest member
RoxannaSta

Latest Threads

Top