Home All Groups Group Topic Archive Search About

Richard Mueller... you out there?

Author
8 Oct 2006 6:18 PM
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!

Author
9 Oct 2006 9:10 AM
Anthony Jones
Show quote Hide quote
"Jim D" <no@spam.com> wrote in message
news:%23%23mXdYw6GHA.3836@TK2MSFTNGP02.phx.gbl...
> 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.  ;)
Are all your drivers up to date? click for free checkup

Author
9 Oct 2006 12:02 PM
SLH
got it working. thanks everyone

Show quoteHide quote
"Anthony Jones" <A**@yadayadayada.com> wrote in message
news:exkDOL46GHA.4620@TK2MSFTNGP02.phx.gbl...
>
> "Jim D" <no@spam.com> wrote in message
> news:%23%23mXdYw6GHA.3836@TK2MSFTNGP02.phx.gbl...
>> 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.
> ;)
>
>
>

Bookmark and Share