How to post Repeating form elements genned via while loop
Posted: Wed Nov 25, 2009 5:10 pm
I am generating a repeating row of form elements (input boxes etc.). How do I set it up the insert code so each row of form elements is inserted into a back-end table. I know how to set up an insert routine and there are some elements I want to add like a unique ID for the group of inserted records to be tied to (I will create a random generator for that). In the meantime though, I want to get an idea how to approach implementing this the insert. Do I need to also generate appended $variables to go with each additional row of form elements. If so, how do I go about generating corresponding variables?
Example of interface:
Example of interface:
Code: Select all
<?
$set = 0;
if(!isset($_SESSION['trueset'])){
$_SESSION['trueset'] = $_GET['trueset'];
}
if(isset($_POST['addaset_x'])){
$_SESSION['trueset'] = $_SESSION['trueset'] + 1;
$trueset = $_SESSION['trueset'];
header( "Location: http://www.url.com/membersarea/add_ex_p ... t=$trueset" );
}
if(isset($_POST['remove'])){
$_SESSION['trueset'] = $_SESSION['trueset'] - 1;
$trueset = $_SESSION['trueset'];
header( "Location: http://www.url.com/membersarea/add_ex_p ... t=$trueset" );
}
$trueset = $_GET['trueset'];
while($set != $trueset){
echo "
<table width=370 border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=37 bgcolor=EAE9E9 align=center><span class=psm_b>Set ";
echo $set + 1;
echo "</span></td>
<td width=5> </td>
<td width=46>
<input type=text name=num_sets maxlength=3 size=3 value=";
echo isset($_POST['num_sets']) ? $_POST['num_sets'] : '';
echo ">
</td>
<td width=5> </td>
<td width=46>
<input type=text name=w8_lbs maxlength=3 size=3 value=";
echo isset($_POST['w8_lbs']) ? $_POST['w8_lbs'] : '';
echo ">
</td>
<td width=5> </td>
<td width=46>
<input type=text style=background-color: #FFF475; name=w8_units maxlength=3 size=3 value=";
echo isset($_POST['w8_units']) ? $_POST['w8_units'] : '';
echo ">
</td>
<td width=5> </td>
<td width=30 align=center>
<input type=checkbox name=w8_spot value=1 ";
if($_POST['w8_spot'] == '1' || $w8_spot == '1') { print 'checked'; }
echo ">";
echo "
</td>
<td width=12> </td>
<td width=84>
<input type=text name=spot_set maxlength=3 size=7 value=";
echo isset($_POST['spot_set']) ? $_POST['spot_set'] : '';
echo ">
</td>
<td width=5> </td>
<td width=39>";
if($set+1 == $trueset){echo "<input type=\"hidden\" name=\"supporttype\" /><a href=\"javascript:getsupport('remove')\"><span class=psm_b>Remove</span></a>";}
echo "</td>
</tr>
<tr>
<td colspan=13 height=5><img src=../images/spacer10.gif width=10 height=5></td>
</tr>
</table>
";
$set = $set + 1;
}
?>