Hi Omer,
The problem with the
Check New Username behavior is that it redirects away from the page where you are validating the username when the name already exists. Even when you redirect to the same page again (addUser.asp for example) you loose your form fields, so you can't show them again. The only form field that is passed in the QueryString is
requsername, which holds the requested username.
To overcome this situation, you'll need to perform the following steps:
1. Create addUser.asp
2. Add a
Record Insertion Form that displays all the fields you want your user to fill in (i.e.
UserName,
LastName,
FirstName,
Password, etc.)
3. Add the
Check New Username behavior.
4. Modify the code that DW inserted for this behavior:
Code:
Dim UserExists
If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
' the username was found - can not add the requested username
MM_qsChar = "?"
If (InStr(1,MM_dupKeyRedirect,"?") >= 1) Then MM_qsChar = "&"
MM_dupKeyRedirect = MM_dupKeyRedirect & _
MM_qsChar & "requsername=" & MM_dupKeyUsernameValue
' Don't redirect here, but set a flag instead
UserExists = True
End If
5. In the rest of your code, you can use the
UserExists boolean to determine further actions, like:
Code:
<%
If UserExists = True Then
Response.Write("This name has already been taken")
End If
%>
6. To ensure that the form keeps its values, you'll need to add these values again to the
value attribute of each HTML control. So, change:
<input type="text" name="Name" value="" size="32">
to
<input type="text" name="Name" value="<%=Request.Form("Name")%>" size="32">
The first time the form loads, Request.Form("Name") will not have a value, so the textbox will be empty. After you have checked the Username, Request.Form("Name") will contain a value, so it will be displayed in the textbox.
By using the UserExists boolean, you can display an error message, or determine whether the user account has been added correctly, and redirect to another page, for example.
I am leaving for holidays in a couple of hours, so I may not be able to respond to further questions for a while.....
HtH
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.