 |
| ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 14th, 2004, 05:06 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
checkboxes help needed!!
Hi im new to asp, just tryin to learn as i go. Basically ive come unstuck whilst trying to create a form which is used to capture a users details, which are added to a members table in sql server then as part of the same form the user ticks some checkboxes to decide which vegetables they want to grow. Im working on a small prototype. the members details go into to the members table however the info from the checkboxes dont go in their corresponding table.
Heres some code:
--the form code
<Form action="register.asp" method="POST">
<input type="hidden" name="action" value="register">
--some of the checkbox code
td>Artichokes</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("artichokes")%>"></td></tr>
<tr>
<td>Beetroot</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("beetroot")%>"></td></tr>
<tr>
<td>Broad Beans</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("broadbeans")%>"></td></tr>
<tr>
<td>Brocolli</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("brocolli")%>"></td></tr>
<tr>
<td>Brussel Sprouts</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("brusselsprouts")%>"></td></tr><tr>
<td>Cabbage</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("cabbage")%>"></td></tr><tr>
--the asp, basically here im tryin to go through each of the checkboxes and for each one that is ticked enter a new row in the table with that username and the veg name.
For item In Request.Form("root")
StrSQL="INSERT INTO veg_other ([username],[veg_name]) VALUES " &_
"('"& fixQuotes(Request.Form("username")) &"','" & fixQuotes(Request.Form("root")(item)) &"')"
objComm.Execute strSQL
Next
Any help would be greatly appreciated.
Thanks
|
|

March 14th, 2004, 05:46 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Request.Form("root") will be a comma separated string of all user checked vegetables...
It is sometimes helpful to print out exactly what you're are dealing with using:
Response.Write(Request("root"))
If you do this, you'll notice that each value is separated by a ", "
(<comma><space>)...
So you would need to parse the comma separated string to extract each check root value using the split() function:
For item In Split(Request.Form("root"),", ")
|
|

March 14th, 2004, 06:13 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the reply.
Im not getting any data, ive tried what you suggested-
Response.Write(Request("root"))- but nothing is being printed.
Is the syntax correct?
For item In Request.Form("root")
StrSQL="INSERT INTO veg_other ([username],[veg_name]) VALUES " &_
"('"& fixQuotes(Request.Form("username")) &"','" & fixQuotes(Request.Form("root")(item)) &"')"
objComm.Execute strSQL
Next
--would that achieve what im trying to do, enter the name of the particular vegetable into the table alongside the relevant username, if its not, do you know what is?
|
|

March 14th, 2004, 10:10 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry for the typo... should read:
For Each item In Split(Request.Form("root"),", ")
' ^ notice the "Each"
Next
Also, do you have the closing </form>? If you don't the form will not post any data.
|
|

March 15th, 2004, 01:50 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Still no luck-no data is going into the table here is the entire code!!!:
<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit
Dim strError, strSQL
IF Request.Form("action")="register" THEN
IF Request.Form("username")="" THEN strError=strError & "-Please enter a username<br>"& vbNewLine
IF Request.Form("password")="" THEN strError=strError & "-Please enter a password<br>" & vbNewLine
IF Request.Form("surname")="" THEN strError=strError & "-Please enter a surname<br>" & vbNewLine
IF Request.Form("forename")="" THEN strError=strError & "-Please enter a forename<br>" & vbNewLine
IF Request.Form("email_address")="" THEN strError=strError & "-Please enter a forename<br>" & vbNewLine
IF Request.Form ("password")<>Request.Form("password_confirm")_
And Request.Form("password")<>"" THEN _
strError= strError & "-Your passwords do not match<br>" & vbNewLine
IF strError="" THEN
%>
<%
On Error Resume Next
StrSQL="INSERT INTO members ([username],[password],[Surname],[Forename],[Email_address]) VALUES " &_
"('"& fixQuotes(Request.Form("username")) &"','" & fixQuotes(Request.Form("password")) &"','" & fixQuotes(Request.Form("surname")) &"','" & fixQuotes(Request.Form("forename")) &"','" & fixQuotes(Request.Form("email_address")) &"')"
objConn.Execute strSQL
IF Err.Number = -2147467259 THEN
strError="-That username is already is use. Please choose another<br>" & vbNewLine
ElseIf Err.Number <> 0 THEN
strError = "-An error has occured." & Err.Number & " : " &_
Err.Description & "<br>" & vbNewLine
ELSE
Response.Redirect "login.asp?msgmsg="&Server.URLEncode("Thank you for registering")
Response.End
END IF
On Error Goto 0
END IF
IF strError<> "" THEN
strError="<p>The Following errors occured:" &_
"<br>" & vbNewLine & strError
END IF
END IF
FUNCTION fixQuotes(item)
fixQuotes=Replace(item,"","")
END FUNCTION
%>
<%
Dim objComm, item
Set ObjComm=Server.CreateObject("ADODB.Connection")
objComm.ConnectionString="DSN=LocalServer;UID=sa;P ASSWORD=redknapp"
objComm.Open
strSQL="Select * From rotation"
For Each item In Split(Request.Form("root"),", ")
StrSQL="INSERT INTO veg_other ([username],[veg_name]) VALUES " &_
"('"& fixQuotes(Request.Form("username")) &"','" & fixQuotes(Request.Form("root")(item)) &"')"
objComm.Execute strSQL
Next
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Organic Rotation Registration</title>
<STYLE TYPE="text/css">
<!--
p{font-family:Verdana}
p{text-align:left;}
p{color:black}
body{background-color:#009933}
a{font-family:Verdana}
H5{font-family:Verdana}
H2{font-family:Verdana}
Form{font-family:Verdana}
-->
</style>
</head>
<body>
<table width="725" border="1" align="center" cellpadding="20" bordercolor="green" bgcolor="white">
<tr>
<td width="765" height="900" valign="top">
<IMG SRC="C:\Documents and Settings\********\My Documents\My Pictures\ologo.bmp" ALT="Organic Rotation"><h2>Member Registration</h2>
<H5>Please fill out the following form to register as a member. Please select which of the following vegetables you wish to grow</H5>
<%=strError%>
<Form action="register.asp" method="POST">
<input type="hidden" name="action" value="register">
<table border="0">
<tr>
<b>Personal Details<b>
<td>Username</td>
<td><input type="text" maxlength=20 name="username"
value="<%=Server.HTMLEncode(Request.Form("username "))%>"> </td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" maxlength=20 name="password"
value="<%=Server.HTMLEncode(Request.Form("password "))%>"> </td>
</tr>
<tr>
<td>Password Confirm</td>
<td><input type="password" maxlength=20 name="password_confirm"
value="<%=Server.HTMLEncode(Request.Form("password _confirm"))%>"> </td>
</tr>
<tr>
<td>Surname</td>
<td><input type="surname" maxlength=20 name="surname"
value="<%=Server.HTMLEncode(Request.Form("surname" ))%>"> </td>
</tr>
<td>Forename</td>
<td><input type="forename" maxlength=20 name="forename"
value="<%=Server.HTMLEncode(Request.Form("forename "))%>"> </td>
</tr>
<td>Email Address</td>
<td><input type="email_address" maxlength=20 name="email_address"
value="<%=Server.HTMLEncode(Request.Form("email_ad dress"))%>"> </td>
</tr>
<td>
<b>Produce to be grown<b>
</td>
<tr><br><tr>
<tr>
<td>Artichokes</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("artichokes")%>"></td></tr>
<tr>
<td>Beetroot</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("beetroot")%>"></td></tr>
<tr>
<td>Broad Beans</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("broadbeans")%>"></td></tr>
<tr>
<td>Brocolli</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("brocolli")%>"></td></tr>
<tr>
<td>Brussel Sprouts</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("brusselsprouts")%>"></td></tr><tr>
<td>Cabbage</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("cabbage")%>"></td></tr><tr>
<td>Carrots</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("carrots")%>"></td></tr>
<td>Cauliflower</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("cauliflower")%>"></td></tr>
<td>Celery</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("celery")%>"></td></tr>
<td>Kale</td>
<td><INPUT TYPE="CHECKBOX" NAME="root" VALUE="<%=Request.Form("kale")%>"></td></tr>
<tr>
<td><input type="submit" align="left" value= "Complete Registration" id=submit1 name=submit1></td>
<td><input type="reset" align="left" value="Reset Form" id=reset1 name=reset1>
</table>
</form>
</body>
</html>
|
|

March 15th, 2004, 02:58 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
When your form page is initially rendered, Request.Form("<veggy>") are empty values, therefore the value of each checkbox control is a empty string.
You need to assign values to each checkbox control. i.e.:
<INPUT TYPE="CHECKBOX" NAME="root" VALUE="kale">
|
|
 |