Click to See Complete Forum and Search --> : re-POST form server side - ?


PisgahMan
05-06-2003, 08:43 AM
I need to post a form back onto itself, and then if there are no errors POST the form to another page. A response.redirect will not work in this case. Is there a way to go this w/o setting a hidden field and doing it via javascript?

cmelnick
05-06-2003, 02:53 PM
Ideally, one Server-Side script should display the form, check the form, and handle the posted data all from one script.

For example, for a login page, you could do the following:
1. If no data has been posted, display the form
2. If data has been posted, check to see if the user exists and has a valid password.
2.a. If user exists and has valid password, say "Thank you"
2.b. If user doesn't exist or invalid password, repost form


<!--- login.asp --->
<%
Dim mesg
Dim formUsername, formPassword
Dim realUsername, realPassword

realUsername = "admin"
realPassword = "12345"

If Request("submit") <> "" Then
formUsername = Request("username")
formPassword = Request("password")
If formUsername <> realUsername Then
mesg = "Invalid username. Try again."
formUsername = ""
' Clear the formUsername so their incorrect username
' will not be displayed in the form
ElseIf formPassword <> realPassword Then
mesg = "Invalid password. Try again."
' This time, leave formUsername alone so the form
' will be automatically filled in with their username
' for their second attempt.
Else
mesg = "Thanks for logging in!"
' Here you can redirect to a welcome page, or whatever
' you want to do with a successful login.
End If

Else
mesg = "Enter your username and password to login."
End If
%>

<html>
<body>
<%=mesg%><br><br>
<form action="login.asp" method="post">
<input type="text" size=20 name="username" value="<%=formUsername%>">
<input type="password" size=20 name="password">
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>
<!--- end login.asp --->