asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Code Samples
Components
Tools
New
Free
Downloads
Vendors
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Here is how to make a form which keep asking questions until they have all been answered correct. The form uses recursion calling itself over and over again until the 0th case where the user has answered all the questions.

<%
Response.Expires=0
Response.Buffer = True

Set SA-Check = CreateObject("SMUM.XCheck.1")

' Assume there is nothing left to ask
QuestionsLeft=False

%>

<HTML>
<BODY>
<H2>SA-Check Verification Example</H2>
<TABLE WIDTH=60%>
<TR>
<TD>
This is the SA-Check Example form, data entered in here is not collected.  This page is an exact duplicate of the 
SA-Check.asp example page found in the Evaluation download.  Please feel free to test SA-Check using the form below.
</TD>
</TR>
</TABLE>
<FORM ACTION="SA-Check.asp" METHOD=POST>
<TABLE>
	<%
		FirstName=Request.Form("FirstName")
		if SA-Check.IsValidName(FirstName) = FALSE then
			QuestionsLeft=True
	%>
	<TR>
		<TD ALIGN=RIGHT>
			<B>First Name</B>
		</TD>
		<TD>
			<INPUT TYPE=TEXT SIZE=40 MAXLENGTH=40 NAME="FirstName" VALUE="<%=FirstName%>">
		</TD>
	</TR>
	<%
		else
	%>
			<INPUT TYPE=HIDDEN NAME="FirstName" VALUE="<%=FirstName%>">
	<%
		end if
	%>

	<%
		LastName=Request.Form("LastName")
		if SA-Check.IsValidName(LastName) = FALSE then
			QuestionsLeft=True
	%>
	<TR>
		<TD ALIGN=RIGHT>
			<B>Last Name</B>
		</TD>
		<TD>
			<INPUT TYPE=TEXT SIZE=40 MAXLENGTH=40 NAME="LastName" VALUE="<%=LastName%>">
		</TD>
	</TR>
	<%
		else
	%>
			<INPUT TYPE=HIDDEN NAME="LastName" VALUE="<%=LastName%>">
	<%
		end if
	%>

	<%
		Address=Request.Form("Address")
		if SA-Check.IsValidAddress(Address) = FALSE then
			QuestionsLeft=True
			if (Len(Address)>0) then
				Suggest=SA-Check.SuggestAddressChange(Address)
			end if
	%>
	<TR>
		<TD ALIGN=RIGHT>
			<B>Address</B>
		</TD>
		<TD>
			<INPUT TYPE=TEXT SIZE=40 MAXLENGTH=70 NAME="Address" VALUE="<%=Address%>">
		</TD>
		<%
		if Len(Suggest) then
		%>
		<TD>
			Problem Areas: <%=Suggest%>
		</TD>
		<%
		end if
		%>
	</TR>
	<%
		else
	%>
			<INPUT TYPE=HIDDEN NAME="Address" VALUE="<%=Address%>">
	<%
		end if
	%>

	<%
		City=Request.Form("City")
		if SA-Check.IsValidCity(City) = FALSE then
			QuestionsLeft=True
	%>
	<TR>
		<TD ALIGN=RIGHT>
			<B>City</B>
		</TD>
		<TD>
			<INPUT TYPE=TEXT SIZE=40 MAXLENGTH=70 NAME="City" VALUE="<%=City%>">
		</TD>
	</TR>
	<%
		else
	%>
			<INPUT TYPE=HIDDEN NAME="City" VALUE="<%=City%>">
	<%
		end if
	%>

	<%
		State=Request.Form("State")
		if SA-Check.IsValidState(State) = FALSE then
			QuestionsLeft=True
	%>
	<TR>
		<TD ALIGN=RIGHT>
		<B>State</B>
		</TD>
		<TD>
		<SELECT NAME="State">
		<%
		For Each State In SA-Check.States
		%>
		<OPTION><%=State%>
		<%
		Next
		%>
		</SELECT>
		</TD>
	</TR>
	<%
		else
	%>
			<INPUT TYPE=HIDDEN NAME="State" VALUE="<%=State%>">
	<%
		end if
	%>

	<%
		ZipCode=Request.Form("ZipCode")
		if SA-Check.IsValidUSZipCode(ZipCode) = FALSE then
			QuestionsLeft=True
	%>
	<TR>
		<TD ALIGN=RIGHT>
			<B>Zip Code</B>
		</TD>
		<TD>
			<INPUT TYPE=TEXT SIZE=5 MAXLENGTH=10 NAME="ZipCode" VALUE="<%=ZipCode%>">
		</TD>
	</TR>
	<%
		else
	%>
			<INPUT TYPE=HIDDEN NAME="ZipCode" VALUE="<%=ZipCode%>">
	<%
		end if
	%>

</TABLE>
<%
	if QuestionsLeft = True then
%>
<INPUT TYPE=SUBMIT>
<%
	end if
%>
</FORM>

<%
	if QuestionsLeft = False then
%>
<H2>All Questions Have been passed SA-Check Verification</H2>
<TABLE WIDTH=60%>
<TR>
<TD>
Here is where you would add code to write your data to the database using ADO.
</TD>
</TR>
</TABLE>
<%
	End if
%>
</BODY>
</HTML>





email this code sample to a colleague

Related Products
SA-Check
SA-Check is the server control for data validation. Online forms collect data about users and often write straight to a database. However when you go to analyze the data, you realize that many users have typed in all 'X's or incorrectly entered the information. This becomes more of a problem when there is something behind the form, such as a free download or a restricted area, and the user receives the prize without having to fill in the form correctly. SA-Check can substantially reduce this type of invalid data entry. SA- Check is a COM Object that can be used in Active Server pages to clean and check form data before it is written to a database. SA-Check verifies addresses, states, provinces, credit cards, phone numbers, email, URLs, and countries -- and prevents input with profanity to make sure that the user's input is correct. SA-Check allows the Web programmer to instruct the server to ask the question many times until it is answered correctly. Consequentially, the user corrects the entries before the data ever is written to the database. Use in any environment that supports COM or Automation including ASP, Windows Scripting Host, VB, Visual C++, and Internet Explorer.
[Top]

Support the Active Server Industry



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers