Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP - Re-Populate Form on Error

Status
Not open for further replies.

BigDavieM

Technical User
Joined
Aug 29, 2003
Messages
2
Location
GB
Can anyone help me re-populate a form with completed data when a user selects an incorrect password or a username that already exists, to save the user re-inputting all details when only one aspect is incorrect or unusable?

My code is ASP using SQL statements, and seems to need a type of "If Update=True" statement. I can get a link to return to the Registration Form page, but with ALL fields blank again.

The following are excerpts from (1)CUSTFORM.ASP and
(2)CUSTADD.ASP (which writes back to custform.asp if errors).

CUSTFORM.ASP

<!-- REGISTRATION FORM -->
<FORM ACTION=&quot;custadd.asp?CartID=<%=CartID%>&quot; NAME=&quot;formUser&quot; METHOD=&quot;post&quot;
onSubmit=&quot;justValidating=false; return validateForm(formUser)&quot;>
<P>Please provide the following information to register an account:</P>
<!-- Form Data -->
<TABLE BORDER=&quot;0&quot;>
<TR><TD>First Name:</TD>
<TD> <INPUT TYPE=&quot;text&quot; SIZE=&quot;20&quot; NAME=&quot;FName&quot;
VALUE=&quot;<%=Request.Form(&quot;FName&quot;)%>&quot;></TD></TR>
<TR><TD>Last Name:</TD>
<TD><INPUT TYPE=&quot;text&quot; SIZE=&quot;20&quot; NAME=&quot;LName&quot;
VALUE=&quot;<%=Request.Form(&quot;LName&quot;)%>&quot;></TD></TR>
<TR><TD>Email:</TD>
<TD><INPUT TYPE=&quot;text&quot; SIZE=&quot;30&quot; NAME=&quot;Email&quot;
VALUE=&quot;<%=Request.Form(&quot;Email&quot;)%>&quot;></TD></TR>
<TR><TD COLSPAN=2>Please create a UserName and Password.
Record these in a safe place, as you will use them in the future
to sign in.</TD></TR>
<TR><TD>UserName:</TD>
<TD><INPUT TYPE=&quot;text&quot; SIZE=&quot;20&quot; NAME=&quot;UserName&quot;
VALUE=&quot;<%=Request.Form(&quot;UserName&quot;)%>&quot;></TD></TR>
<TR><TD>Password:</TD>
<TD><INPUT TYPE=&quot;password&quot; SIZE=&quot;20&quot; NAME=&quot;Password&quot;
VALUE=&quot;<%=Request.Form(&quot;Password&quot;)%>&quot;></TD></TR>
<TR><TD>Verify Password:</TD>
<TD><INPUT TYPE=&quot;Password&quot; SIZE=&quot;20&quot; NAME=&quot;VerPword&quot;></TD></TR>
<TR><TD></TD>
<TD COLSPAN=2><BR>
<INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Submit&quot;>
  <INPUT TYPE=&quot;Reset&quot; VALUE=&quot;Reset&quot; >
  <INPUT ONCLICK=&quot;JustValidating=true; validateForm(this.form)&quot;
TYPE=BUTTON VALUE= Validate></TD></TR>

</TABLE>
</FORM>

<%
Response.Write &quot;<TABLE BORDER=0 WIDTH=600>&quot; &_
&quot;<TR><TD WIDTH=200><A HREF='itempage.asp?CartID=&quot; & CartID & &quot;'>&quot; &_
&quot;Category Details</A></TD>&quot; &_
&quot;<TD WIDTH=200>New User (Complete Form)</TD>&quot; &_
&quot;<TD WIDTH=200><A HREF='custadd.asp?CartID=&quot; & CartID & &quot;'>Login</A>&quot; &_
&quot; (Existing Customers)</TD></TR>&quot; &_
&quot;</TABLE>&quot;
%>



CUSTADD.ASP

'CHECK WHETHER USERNAME ALREADY IN USE
While Not myRS.EOF
If myRS(&quot;UserName&quot;) = UserName Then
Used = &quot;yes&quot;
End If
myRS.MoveNext
Wend

'IF USERNAME ALREADY USED, ADVISE TO CHOOSE ANOTHER
If Used = &quot;yes&quot; Then
Response.Write &quot;<DIV ALIGN=CENTER><P>The UserName &quot; & UserName &_
&quot; is already taken. Please <A HREF='custform.asp?CartID=&quot; & CartID &_
&quot;'>go back</A> and choose another&quot; &_
&quot;</DIV>&quot;
Else
'ACCEPT INPUT USERNAME
myRS.Close
myRS.Open &quot;Customers&quot;, strConnect, adOpenKeyset, adLockOptimistic
myRS.AddNew
' ADD NEW USER DETAILS
myRS(&quot;UserName&quot;) = UserName
myRS(&quot;FName&quot;) = FName
myRS(&quot;LName&quot;) = LName
myRS(&quot;Address&quot;) = Address
myRS(&quot;City&quot;) = City
myRS(&quot;County&quot;) = County
myRS(&quot;PostCode&quot;) = PostCode
myRS(&quot;Country&quot;) = Country
myRS(&quot;Phone&quot;) = Phone
myRS(&quot;Email&quot;) = Email
myRS(&quot;Password&quot;) = Password
myRS(&quot;UpdateD&quot;) = Date
myRS(&quot;UpdateT&quot;) = Time
myRS.Update

Thanks
Davie

 
The real trick here is to place the form in a sub/end sub routine and make use of the VALUE attribute of the html form element

Then when the crtieria is (or isn't) met to call the form the variables are then set and can be filled

Code:
'basically the code looks like this:
if not request.form(&quot;submit&quot;) then
   call show_form()
else
   call validate()
end if

sub show_form()
  'html [and asp] code to create the form
end sub

sub validate()
  'code to validate the user data
  'code to update the db
  'confirmation of successful update
end sub

Note: the form action attribute references this same page as everything is contained in this one page

hth

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
Thanks. sorry for delay. I will give this a try when I get a chance and report back.

Davie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top