Returning to a form

S

Stewart

Hello I hope someone can help me.

I have a form page a user needs to fill out. I want to be
able to send the user back to the form once it is
submitted and an error in processing occurs, for example
if they have an illigal charcter in the form somewhere.
The whole form wouldn't need to be retyped, just the
field in question.

How can I send the user back to the form they just
submitted to correct an entry?
 
R

Ray at

I assume that you are not posting back to the same page, huh? You can use
session variables then, as such. You could also use a querystring, but I
find that to get messy and less than ideal. Here's a simple example:


page1.asp:

<%
Dim aErrors(1)
aErrors(0) = ""
aErrors(1) = "Your username may not contain a space."
sUsername = Session("Username")
Session.Contents.Remove("Username")
iErrorID = CInt(Request.Querystring("e"))
%>
<form method="post" action="page2.asp">
<table>
<% If iErrorID > 0 Then %>
<tr>
<td colspan="2"><%=aErrors(iErrorID)%></td>
</tr>
<% End If %>
<tr>
<td>Pick a username</td>
<td><input name="txtUsername" type="text" value="<%=sUsername%>" />
</tr>

<tr>
<td colspan="2" align="right"><input type="submit" /></td>
</tr>
</table>
</form>


page2.asp:

<%
Dim sUsername
sUsername = Trim(Request.Form("txtUsername"))
If Instr(sUsername, " ") > 0 Then
Session("Username") = sUsername
Response.Redirect "page1.asp?e=1"
Else
Session.Contents.Remove("Username")
Response.Write "The username that you entered, " & sUsername & " does not
contain any spaces. Good job."
End If
%>

Ray at home
 

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

No members online now.

Forum statistics

Threads
474,123
Messages
2,570,736
Members
47,289
Latest member
KathrynSta

Latest Threads

Top