Forums
This topic is locked
ALL form fields empty if validity check fails on 1
25 Mar 2006 03:37:14 Kim M posted:
I have a registration page with required fields - username, password, firstname, lastname, email address.I have a serious of checks to ensure that all fields are completed - so if one field is missing (or the email address is not valid), then it returns a message which is written into the page after the Submit button is clicked (form post). If all fields are completed correctly, then the form is submitted by email and entered into the database - and the page redirects to the login screen.
The thing that is annoying me, however, is if a user enteres all the fields (name, username, email address) but maybe to choose a password - when they hit the Submit the page refreshes with the text "Please enter a password" - and all the form fields are cleared/emptied - and they have to not only enter the password, but also have to enter all the other information again.
Is there a way that I can get the information that they have entered into the form fields to stay on the page?
Cheers,
Kim
Replies
Replied 25 Mar 2006 22:12:29
25 Mar 2006 22:12:29 micah santos replied:
this is my way to validates user's input.
VALIDATE_INPUT.ASP
<%
// Variables
Dim valid_input
Dim gbName,gbUser,gbPass,gbEmail
gbName = Trim(Request.Form("name")
gbUser = Trim(Request.Form("username")
gbPass = Trim(Request.Form("password")
gbEmail = Trim(Request.Form("email")
valid_input = TRUE
If Len(gbName) = 0 Then
valid_input = FALSE
End If
// Mininum characters for username and password up to 6
If Len(gbUser) = 0 or Len(gbUser) < 6 Then
valid_input = FALSE
End If
If Len(gbPass) = 0 or Len(gbPass) < 6 Then
valid_input = FALSE
End If
// Email @ sign validation using 6 minimum characters
If Len(gbEmail) < 6 or InStr(gbEmail,"@"=0 Then
valid_input = FALSE
End If
// If some fields are not filled up
If NOT valid_input Then
// If you want to redirect user to another page
response.redirect "invalid.asp"
// Or if you want to simply return user to the same form page, just ignore the first one
// Try using Session variables
Dim errmsg
Session("errmsg" = "Please check your input!"
response.redirect "registration.asp"
// If all fields are filled up
ELSE
// Save records into the database & clear session variable
Session("errmsg" = ""
END IF
%>
REGISTRATION.ASP
<html>
<head>
<title>Registration</title>
</head>
<body>
<form method=post action="validate_input.asp">
<%
If Session("errmsg" <> "" Then
response.write session("errmsg" & "<br><br>"
End If
%>
Name <br>
<input type=text name="name" size="25" maxlength="25"><br>
Email <br>
<input type=text name="email" size="25" maxlength="50"><br>
Username (6 chars min.)
<input type=text name="username" size="25" maxlength="25"><br>
Passowrd (6 chars min.)
<input type=password name="name" size="25" maxlength="25"><br><br>
<input type=submit name="Register" name=submit>
</form>
</body>
</html>
VALIDATE_INPUT.ASP
<%
// Variables
Dim valid_input
Dim gbName,gbUser,gbPass,gbEmail
gbName = Trim(Request.Form("name")
gbUser = Trim(Request.Form("username")
gbPass = Trim(Request.Form("password")
gbEmail = Trim(Request.Form("email")
valid_input = TRUE
If Len(gbName) = 0 Then
valid_input = FALSE
End If
// Mininum characters for username and password up to 6
If Len(gbUser) = 0 or Len(gbUser) < 6 Then
valid_input = FALSE
End If
If Len(gbPass) = 0 or Len(gbPass) < 6 Then
valid_input = FALSE
End If
// Email @ sign validation using 6 minimum characters
If Len(gbEmail) < 6 or InStr(gbEmail,"@"=0 Then
valid_input = FALSE
End If
// If some fields are not filled up
If NOT valid_input Then
// If you want to redirect user to another page
response.redirect "invalid.asp"
// Or if you want to simply return user to the same form page, just ignore the first one
// Try using Session variables
Dim errmsg
Session("errmsg" = "Please check your input!"
response.redirect "registration.asp"
// If all fields are filled up
ELSE
// Save records into the database & clear session variable
Session("errmsg" = ""
END IF
%>
REGISTRATION.ASP
<html>
<head>
<title>Registration</title>
</head>
<body>
<form method=post action="validate_input.asp">
<%
If Session("errmsg" <> "" Then
response.write session("errmsg" & "<br><br>"
End If
%>
Name <br>
<input type=text name="name" size="25" maxlength="25"><br>
Email <br>
<input type=text name="email" size="25" maxlength="50"><br>
Username (6 chars min.)
<input type=text name="username" size="25" maxlength="25"><br>
Passowrd (6 chars min.)
<input type=password name="name" size="25" maxlength="25"><br><br>
<input type=submit name="Register" name=submit>
</form>
</body>
</html>
Replied 26 Mar 2006 07:06:50
26 Mar 2006 07:06:50 Kim M replied:
thanks for that - will give that a go....
Kim
Kim