So, I have this problem. I need to parse a form into repetitive chunks to write to a db. First, here are the tables:
Next here is (some) of the form:
This part I write to the first database and return the ID, no problem, but then I hit this part of the form:
which is the repetitive part of the form with five different fields being repeated and just incremented by one each time. This data is written to the second table with the id from the first table (got the id passed, no problem), my problem come in trying to break it into those 5 fields and then stop when I hit an empty data set. So, for instance, they enter the leader info and then data for 6 participants. I would want to iterate thru the participant posting process 6 times for the data they have entered, and then when I come across an empty field, exit that process. And, I can change the way the basic page is written if that would make it easier. It is a stand-alone page, so I can make any changes that I need to if you can think of some way to make this whole thing flow better.
Below is the code that I started, but it isn't quite right and I can't get it to stop on an empty field. I don't have all of my iterations, but here is the last one:
Thanks for any help you can give me.
Willie
Code:
CREATE TABLE [dbname].[tbl_ss_group_leaders] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[church] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[age_group] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[trip] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[leader_name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[leader_email] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[emerg_name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[emerg_phone] [varchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[emerg_relation] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[radiobutton] [varchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[van_number] [int] NOT NULL ,
[van_drivers] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[insertdate] [datetime] NOT NULL ,
[processdate] [datetime] NULL
)
Code:
CREATE TABLE [dbname].[tbl_ss_group_participants] (
[ss_id] [int] NOT NULL ,
[name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[email] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[gender] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[age] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[grade_comp] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[insertdate] [datetime] NOT NULL ,
[processdate] [datetime] NULL
)
Next here is (some) of the form:
Code:
<form action="formname.asp" name="drop_list" method="post" onKeyUp="highlight(event)"
onClick="highlight(event)" onSubmit="return isFormComplete(this);" ID="Form1">
<div align="center">
<table width="502" border="0" align="center" cellpadding="5" cellspacing="0" ID="Table1">
<tr>
<td width="100%" height="146" valign="top" class="style3"><span class="style5">Group Information and Participant List <br>
<br>
<table width="565" align="center" cellpadding="2" ID="Table2">
<tr>
<td colspan="3" class="style3"><div align="center"><strong>GENERAL INFORMATION</strong></font></div>
</td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Group/Church Name</div>
</td>
<td class="style3"><label>
<input name="church" type="text" id="church" size="50">
</label>
</td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Leader/Contact Person Name:</div>
</td>
<td class="style3"><label>
<input name="leader_name" type="text" id="leader_name" size="50">
</label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Leader/Contact Person Email:</div>
</td>
<td class="style3"><label>
<input name="leader_email" type="text" id="leader_email" size="50">
</label></td>
</tr>
.
.
.
This part I write to the first database and return the ID, no problem, but then I hit this part of the form:
Code:
<tr>
<td colspan="3" class="style3"><div align="center"><strong>LIST ALL PARTICIPANTS BELOW (ADULTS INCLUDED)<br></strong></div></td>
</tr>
<tr>
<td width="15" class="style3"><div align="right"><strong>1</strong></div></td>
<td width="159" class="style3"><div align="right">Name</div></td>
<td class="style3"><label><input name="name1" type="text" id="1=name1" size="60"></label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Email</div></td>
<td class="style3"><label><input name="email1" type="text" id="email1" size="60"></label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Gender</div></td>
<td class="style3"><label><input type="radio" name="gender1" value="male" ID="Radio1">Male</label>
<label><input type="radio" name="gender1" value="female" ID="Radio2">Female</label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Adult or Camper?</div></td>
<td class="style3"><label><input type="radio" name="age1" value="adult" ID="Radio3">Adult</label>
<label><input type="radio" name="age1" value="camper" ID="Radio4">Camper</label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Grade completed:</td>
<td><select name="grade_comp1" ID="Select1">
<option value="">(Please select an option)</option>
<option value="adult">Adult</option>
<option value="6">6th Grade</option>
<option value="7">7th Grade</option>
<option value="8">8th Grade</option>
<option value="9">9th Grade</option>
<option value="10">10th Grade</option>
<option value="11">11th Grade</option>
<option value="12">12th Grade</option>
</select></td>
</tr>
<tr>
<td colspan="3" class="style3"> </td>
</tr>
<tr>
<td class="style3"><div align="right"><strong>2</font></strong></div></td>
<td class="style3"><div align="right">Name</div></td>
<td class="style3"><label><input name="name2" type="text" id="name2" size="60"></label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Email</div></td>
<td class="style3"><label><input name="email2" type="text" id="email2" size="60"></label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Gender</div></td>
<td class="style3"><label><input type="radio" name="gender2" value="male" ID="Radio5">Male</label>
<label><input type="radio" name="gender2" value="female" ID="Radio6">Female</label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Adult or Camper?</div></td>
<td class="style3"><label><input type="radio" name="age2" value="adult" ID="Radio7">Adult</label>
<label><input type="radio" name="age2" value="camper" ID="Radio8">Camper</label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Grade completed:</td>
<td><select name="grade_comp2" ID="Select2">
<option value="">(Please select an option)</option>
<option value="adult">Adult</option>
<option value="6">6th Grade</option>
<option value="7">7th Grade</option>
<option value="8">8th Grade</option>
<option value="9">9th Grade</option>
<option value="10">10th Grade</option>
<option value="11">11th Grade</option>
<option value="12">12th Grade</option>
</select></td>
</tr>
.
.
.
<tr>
<td class="style3"><div align="right"><strong>n</font></strong></div></td>
<td class="style3"><div align="right">Name</div></td>
<td class="style3"><label><input name="namen" type="text" id="Text1" size="60"></label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Email</div></td>
<td class="style3"><label><input name="emailn" type="text" id="Text2" size="60"></label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Gender</div></td>
<td class="style3"><label><input type="radio" name="gendern" value="male" ID="Radio9">Male</label>
<label><input type="radio" name="gendern" value="female" ID="Radio10">Female</label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Adult or Camper?</div></td>
<td class="style3"><label><input type="radio" name="agen" value="adult" ID="Radio11">Adult</label>
<label><input type="radio" name="agen" value="camper" ID="Radio12">Camper</label></td>
</tr>
<tr>
<td colspan="2" class="style3"><div align="right">Grade completed:</td>
<td><select name="grade_compn" ID="Select3">
<option value="">(Please select an option)</option>
<option value="adult">Adult</option>
<option value="6">6th Grade</option>
<option value="7">7th Grade</option>
<option value="8">8th Grade</option>
<option value="9">9th Grade</option>
<option value="10">10th Grade</option>
<option value="11">11th Grade</option>
<option value="12">12th Grade</option>
</select></td>
</tr>
which is the repetitive part of the form with five different fields being repeated and just incremented by one each time. This data is written to the second table with the id from the first table (got the id passed, no problem), my problem come in trying to break it into those 5 fields and then stop when I hit an empty data set. So, for instance, they enter the leader info and then data for 6 participants. I would want to iterate thru the participant posting process 6 times for the data they have entered, and then when I come across an empty field, exit that process. And, I can change the way the basic page is written if that would make it easier. It is a stand-alone page, so I can make any changes that I need to if you can think of some way to make this whole thing flow better.
Below is the code that I started, but it isn't quite right and I can't get it to stop on an empty field. I don't have all of my iterations, but here is the last one:
Code:
SET cmd = server.CreateObject("ADODB.Command")
with cmd
.ActiveConnection = conn
.CommandText = "dbname.sp_insert_ss_group_leaders"
.CommandType = adCmdStoredProc
'Input Parameters
.Parameters.Append .createparameter("@church", adVarChar, adParamInput, 50, request("church"))
.Parameters.Append .createparameter("@age_group", adVarChar, adParamInput, 50, request("category"))
.Parameters.Append .createparameter("@trip", adVarChar, adParamInput, 50, request("subcat"))
.Parameters.Append .createparameter("@leader_name", adVarChar, adParamInput, 50, request("leader_name"))
.Parameters.Append .createparameter("@leader_email", adVarChar, adParamInput, 50, request("leader_email"))
.Parameters.Append .createparameter("@emerg_name", adVarChar, adParamInput, 50, request("emerg_name"))
.Parameters.Append .createparameter("@emerg_phone", adVarChar, adParamInput, 50, request("emerg_phone"))
.Parameters.Append .createparameter("@emerg_relation", adVarChar, adParamInput, 50, request("emerg_relation"))
.Parameters.Append .createparameter("@radiobutton", adVarChar, adParamInput, 4, request("radiobutton"))
.Parameters.Append .createparameter("@van_number", adInteger, adParamInput, , request("van_number"))
.Parameters.Append .createparameter("@van_drivers", adVarChar, adParamInput, 255, request("van_drivers"))
Set rs=.Execute
end with
set cmd = nothing
response.Write "the group id is: " & rs(0) & "<br>"
Dim i : i=1
Dim j
Dim name, age, gender, email, grade_comp
for x = 12 to Request.Form.count()
j=1
for j = 1 to 5
If len(Request.Form.item(x)) <> "0" THEN
name="name"&i
email="email"&i
gender="gender"&i
age="age"&i
grade_comp="grade_comp"&i
name=request(name)
email=request(email)
gender=request(gender)
age=request(age)
grade_comp=request(grade_comp)
Response.Write Request.Form.item(x) & " " & name & "<br>"
Response.Write Request.Form.item(x) & " " & email & "<br>"
Response.Write Request.Form.item(x) & " " & gender & "<br>"
Response.Write Request.Form.item(x) & " " & age & "<br>"
Response.Write Request.Form.item(x) & " " & grade_comp & "<br>"
ELSE
Exit for
END IF
i=i+1
j=j+1
next
next
Thanks for any help you can give me.
Willie