How to post Repeating form elements genned via while loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
edawson003
Forum Contributor
Posts: 133
Joined: Thu Aug 20, 2009 6:34 am
Location: Los Angeles, CA - USA

How to post Repeating form elements genned via while loop

Post by edawson003 »

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:
Set_Add.gif
Set_Add.gif (8.52 KiB) Viewed 97 times

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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</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>&nbsp;</td>
                      <td width=39>";
                      if($set+1 == $trueset){echo "<input type=\"hidden\" name=\"supporttype\" /><a href=\"javascript&#058;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;
                 }  
                 ?>
Post Reply