How to generate a row of form elements based on a $variable
Posted: Fri Nov 20, 2009 10:29 pm
I am trying to set up an application that will allow a user to generate a row of form elements based on a $variable that would increase in numerical value based on a form action such as submit. Also, vice a versa, I would like to remove form element rows as well. I made an attempt but so far I am only able to add row and that is it. For my approach to work I need to set a php element/$variable that I can keep adding a value to incrementally. I feel like I am almost there and just missing a key piece. Can someone gimme a clue? Maybe my whole approach is flawed, so please dont be bashful.
Code: Select all
<?
$set = 0;
$endset = 3;
if(isset($_POST['add_a_set_x'])){
$endset1[] = 1;
$endset = $endset + 1;
}
while($set != $endset){
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 == $endset){echo "<span class=psm_b>Remove</span>";}
echo "</td>
</tr>
<tr>
<td colspan=13 height=5><img src=../images/spacer10.gif width=10 height=5></td>
</tr>
</table>
";
$set = $set + 1;
}
?>