SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Shropshire
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help improving form arrays

    I have a form, of which the relevant part is below (sorry it is a very large form):
    PHP Code:
    <form name="add-classes" action="confirm-classes.php" method="post">
                        <input type="hidden" name="select_classes" value="1" />
                        <input type="hidden" name="more_dogs_ok" value="<?php echo $_GET['more_dogs_ok']?>" />
                                                        <div class="formheadlarge">Main Classes  </div>
                                                        <div class="formlarge">
                            <table width="99%" class="list">
                              <tr><td colspan="3">Classes you can enter based on your dog's height and grade</td></tr>
                              <?php if (!empty($class_info)) { ?>
                              <tr><td colspan="3"><strong><?php echo $class_info;?></strong></td></tr>
                              <?php ?>
                              <tr><td colspan="3" align="right"><a href="#" onclick="SetAllCheckBoxes('add-classes', 'gradeclass', true);return false;">Select All</a>&nbsp;
                                <a href="#" onclick="SetAllCheckBoxes('add-classes', 'gradeclass', false);return false;">De-Select All</a></td></tr>
                              <tr>
                                <td class="header">Class</td>
                                <td align="right" class="header">Handler</td>
                                <td width="6%" class="header">                            </td>
                              </tr>
                        <?php
                        
                        
    if ($owner_id==$_SESSION['judge_id']) {
                        
    $show_days = new shows;
                        
    $show_days->show_id=$_SESSION['show_id'];
                        
    $show_days->get_show_days_not_judging();
                        }
                        else {
                        
    $show_days = new shows;
                        
    $show_days->show_id=$_SESSION['show_id'];
                        
    $show_days->get_show_days();
                        }
                        
                        while (
    $dayrow=$show_days->get_row()) { 
                        
                        
    $class_grades_found=0;
                        
    $classes = new classes;
                        
    $classes->show_id=$_SESSION['show_id'];
                        
    $classes->height_id=$_SESSION['height_id'];
                        
    $classes->grade_id=$_SESSION['grade_id'];
                        
    $classes->breed_id=$_SESSION['breed_id'];
                        
    $classes->day_id=$dayrow['day_id'];
                        if (
    $_SESSION['show_type']==5) {
                        
    $classes->get_inter_classes();
                        }
                        else {
                        
    $classes->get_grade_classes();
                        }
                        
    $class_grades_found=$classes->total_rows;
                        
    ?>
                        <tr><td colspan="3"><h3><?php echo $dayrow['day'];?> - <span class="highlight"><?php if ($dayrow['max_classes']>0) { echo 'Please only select '.$dayrow['max_classes'].' classes';} ?></span></h3></td></tr>
                          <?php
                          $height
    ='';

                          while (
    $graderow=$classes->get_row()) { 
                          if (
    $graderow['height']!='All') {
                          
    $height=' '.$graderow['height'].' ';
                          }
                          
    ?>
                              <tr>
                                  <td width="63%"><?php echo '<strong>'.$graderow['class_number'].'</strong>:'.$height.''.$graderow['class_name'];?>
                                <?php if ($graderow['class_qual']=='t') { echo ' (Q)';} if ($graderow['class_special']=='t') {echo ' (S)';}?></td>
                    <td width="31%" align="right"><select name="handler_id[<?php echo $graderow['class_number']?>]" class="fields">
                                <?php
                                $handlers 
    = new handlers;
                                
    $handlers->customer_id=$_SESSION['customer_id'];
                                
    $handlers->get_accnt_dog_handlers();
                                
                                while (
    $handlerrow=$handlers->get_row()) { ?>
                                <option value="<?php echo $handlerrow['handler_id']?><?php if ($handlerrow['handler_id']==$main_handler_id) {echo 'selected';}?>><?php echo $handlerrow['handler_name'].' '.$handlerrow['handler_surname'];?></option>
                                <?php ?>
                                </select></td>
                                <td align="right">
                                <input type="checkbox" name="class_number[]" id="gradeclass" value="<?php echo $graderow['class_number']?>" /></td>
                              </tr>
                              <?php if($class_grades_found 1) { ?>
                             <tr>
                               <td colspan="3" class="dot"></td>
                              </tr>
                            <?php } } } if ($class_grades_found=0) { ?>
                              <tr><td colspan="3">There are no classes available to enter based on your dog's height and grade.</td></tr>
                              <?php ?>
                              </table>
                          </div>
                          <?php
                        $veteran_count
    =0;
                        if (
    $owner_id==$_SESSION['judge_id']) {
                        
    $veteran_show_days = new shows;
                        
    $veteran_show_days->show_id=$_SESSION['show_id'];
                        
    $veteran_show_days->get_show_days_veteran_classes_not_judging();
                        }
                        else {
                        
    $veteran_show_days = new shows;
                        
    $veteran_show_days->show_id=$_SESSION['show_id'];
                        
    $veteran_show_days->get_show_days_veteran_classes();
                        }
                        
    $veteran_count=$veteran_show_days->total_rows;
                        
                        if (
    $veteran_count>0) {
                        
    ?>
                            <div class="formheadlarge">Veteran Classes</div>
                            <div class="formlarge">
                            <table width="100%" class="list">
                              <tr><td colspan="3" align="right"><a href="#" onclick="SetAllCheckBoxes('add-classes', 'veteranclass', true);return false;">Select All</a>&nbsp;
                                <a href="#" onclick="SetAllCheckBoxes('add-classes', 'veteranclass', false);return false;">De-Select All</a></td></tr>
                              <tr>
                              <tr>
                                <td class="header">Class</td>
                                <td align="right" class="header">Handler</td>
                                <td width="6%" class="header">                            </td>
                              </tr>
                        <?php
                        
    while ($dayrow2=$veteran_show_days->get_row()) {
                        
                        
    $veteran_classes_count=0;
                        
    $veteran_classes = new classes;
                        
    $veteran_classes->show_id=$_SESSION['show_id'];
                        
    $veteran_classes->height_id=$_SESSION['height_id'];
                        
    $veteran_classes->grade_id=$_SESSION['grade_id'];
                        
    $veteran_classes->day_id=$dayrow2['day_id'];
                        if (
    $_SESSION['height_id']>1) {
                        
    $veteran_classes->get_small_veteran_classes();
                        }
                        else {
                        
    $veteran_classes->get_veteran_classes();
                        }
                        
    $veteran_classes_count=$veteran_classes->total_rows;
                        
    ?>
                        <tr><td colspan="3"><h3><?php echo $dayrow2['day'];?></h3></td></tr>
                          <?php while ($veteranrow=$veteran_classes->get_row()) {
                                  if (
    $veteranrow['height']!='All') {
                                
    $height=$veteranrow['height'];
                                }
                                else {
                                
    $height='';
                                }
                          
    ?>
                              <tr>
                                  <td width="63%"><?php echo '<strong>'.$veteranrow['class_number'].'</strong>: '.$height.' '.$veteranrow['class_name'];?><?php if ($veteranrow['height']=='All') { echo ' (All heights)';}?>
                                <?php if ($veteranrow['class_qual']=='t') { echo ' (Q)';} if ($veteranrow['class_special']=='t') {echo ' (S)';}?></td>
                                <td width="31%" align="right"><select name="handler_id[<?php echo $veteranrow['class_number']?>]" class="fields">
                                <?php 
                                $handlers2 
    = new handlers;
                                
    $handlers2->customer_id=$_SESSION['customer_id'];
                                
    $handlers2->get_accnt_dog_handlers();
                        
                                while (
    $handlerrow2=$handlers2->get_row()) { ?>
                                <option value="<?php echo $handlerrow2['handler_id']?><?php if ($handlerrow2['handler_id']==$main_handler_id) {echo 'selected';}?>><?php echo stripslashes($handlerrow2['handler_name']).' '.stripslashes($handlerrow2['handler_surname']);?></option>
                                <?php ?>
                                </select></td>
                                <td align="right">
                                <input type="checkbox" name="class_number[]" id="veteranclass" value="<?php echo $veteranrow['class_number']?>" /></td>
                              </tr>
                            <?php } } ?>
                            </table>
                          </div>
                          <?php }
                        
    $anysize_count=0;
                        if (
    $owner_id==$_SESSION['judge_id']) {
                        
    $anysize_show_days = new shows;
                        
    $anysize_show_days->show_id=$_SESSION['show_id'];
                        
    $anysize_show_days->get_show_days_anysize_classes_not_judging();
                        }
                        else {
                        
    $anysize_show_days = new shows;
                        
    $anysize_show_days->show_id=$_SESSION['show_id'];
                        
    $anysize_show_days->get_show_days_anysize_classes();
                        }
                        
    $anysize_count=$anysize_show_days->total_rows;
                        if (
    $anysize_count>0) { ?>
                            <div class="formheadlarge">Any Size Classes</div>
                            <div class="formlarge">
                            <table width="100%" class="list">
                              <tr><td colspan="3" align="right"><a href="#" onclick="SetAllCheckBoxes('add-classes', 'anysizeclass', true);return false;">Select All</a>&nbsp;
                                <a href="#" onclick="SetAllCheckBoxes('add-classes', 'anysizeclass', false);return false;">De-Select All</a></td></tr>
                              <tr>
                              <tr>
                                <td class="header">Class</td>
                                <td align="right" class="header">Handler</td>
                                <td width="6%" class="header">                            </td>
                              </tr>
                        <?php
                        
    while ($dayrow3=$anysize_show_days->get_row()) {
                        
                        
    $anysize_classes_count=0;
                        
    $anysize_classes = new classes;
                        
    $anysize_classes->show_id=$_SESSION['show_id'];
                        
    $anysize_classes->height_id=$_SESSION['height_id'];
                        
    $anysize_classes->grade_id=$_SESSION['grade_id'];
                        
    $anysize_classes->day_id=$dayrow3['day_id'];
                        if (
    $_SESSION['height_id']>1) {
                        
    $anysize_classes->get_small_anysize_classes();
                        }
                        else {
                        
    $anysize_classes->get_anysize_classes();
                        }
                        
    $anysize_classes_count=$anysize_classes->total_rows;
                        
    ?>
                        <tr><td colspan="3"><h3><?php echo $dayrow3['day'];?></h3></td></tr>
                          <?php while ($anysizerow=$anysize_classes->get_row()) {
                                  if (
    $anysizerow['height']!='All') {
                                
    $height=$anysizerow['height'];
                                }
                                else {
                                
    $height='';
                                }
                          
    ?>
                              <tr>
                                  <td width="63%"><?php echo '<strong>'.$anysizerow['class_number'].'</strong>: '.$height.' '.$anysizerow['class_name'];?><?php if ($anysizerow['height']=='All') { echo ' (All heights)';}?>
                                <?php if ($anysizerow['class_qual']=='t') { echo ' (Q)';} if ($anysizerow['class_special']=='t') {echo ' (S)';}?></td>
                                <td width="31%" align="right"><select name="handler_id[<?php echo $anysizerow['class_number']?>]" class="fields">
                                <?php 
                                $handlers3 
    = new handlers;
                                
    $handlers3->customer_id=$_SESSION['customer_id'];
                                
    $handlers3->get_accnt_dog_handlers();
                        
                                while (
    $handlerrow3=$handlers3->get_row()) { ?>
                                <option value="<?php echo $handlerrow3['handler_id']?><?php if ($handlerrow3['handler_id']==$main_handler_id) {echo 'selected';}?>><?php echo $handlerrow3['handler_name'].' '.$handlerrow3['handler_surname'];?></option>
                                <?php ?>
                                </select></td>
                                <td align="right">
                                <input type="checkbox" name="class_number[]" id="anysizeclass" value="<?php echo $anysizerow['class_number']?>" /></td>
                              </tr>
                            <?php } } ?>
                            </table>
                          </div>
                        <?php }
                        if (
    $total_juniors>0) {
                        
    $junior_count=0;
                        if (
    $owner_id==$_SESSION['judge_id']) {
                        
    $junior_show_days = new shows;
                        
    $junior_show_days->show_id=$_SESSION['show_id'];
                        
    $junior_show_days->get_show_days_junior_classes_not_judging();
                        }
                        else {
                        
    $junior_show_days = new shows;
                        
    $junior_show_days->show_id=$_SESSION['show_id'];
                        
    $junior_show_days->get_show_days_junior_classes();
                        }
                        
    $junior_count=$junior_show_days->total_rows;
                        
                        if (
    $junior_count>0) {
                        
    ?>
                            <div class="formheadlarge">Junior Classes</div>
                            <div class="formlarge">
                            <table width="100%" class="list">
                              <tr><td colspan="3" align="right"><a href="#" onclick="SetAllCheckBoxes('add-classes', 'juniorclass', true);return false;">Select All</a>&nbsp;
                                <a href="#" onclick="SetAllCheckBoxes('add-classes', 'juniorclass', false);return false;">De-Select All</a></td></tr>
                              <tr>
                              <tr>
                                <td class="header">Class</td>
                                <td align="right" class="header">Handler</td>
                                <td width="6%" class="header">                            </td>
                              </tr>
                        <?php
                        
    while ($dayrow4=$junior_show_days->get_row()) {
                        
                        
    $junior_classes_count=0;
                        
    $junior_classes = new classes;
                        
    $junior_classes->show_id=$_SESSION['show_id'];
                        
    $junior_classes->height_id=$_SESSION['height_id'];
                        
    $junior_classes->grade_id=$_SESSION['grade_id'];
                        
    $junior_classes->breed_id=$_SESSION['breed_id'];
                        
    $junior_classes->day_id=$dayrow4['day_id'];
                        
    $junior_classes->get_junior_classes();
                        
    $junior_classes_count=$junior_classes->total_rows;
                        
    ?>
                        <tr><td colspan="3"><h3><?php echo $dayrow4['day'];?></h3></td></tr>
                          <?php while ($juniorrow=$junior_classes->get_row()) {
                                  if (
    $juniorrow['height']!='All') {
                                
    $height=$juniorrow['height'];
                                }
                                else {
                                
    $height='';
                                }
                          
    ?>
                              <tr>
                                  <td width="63%"><?php echo '<strong>'.$juniorrow['class_number'].'</strong>: '.$height.' '.$juniorrow['class_name'];?><?php if ($juniorrow['height']=='All') { echo ' (All heights)';}?>
                                <?php if ($juniorrow['class_qual']=='t') { echo ' (Q)';} if ($juniorrow['class_special']=='t') {echo ' (S)';}?></td>
                                <td width="31%" align="right"><select name="handler_id[<?php echo $juniorrow['class_number']?>]" class="fields">
                                <?php 
                                $juniors2 
    = new handlers;
                                
    $juniors2->customer_id=$_SESSION['customer_id'];
                                
    $juniors2->get_junior_accnt_handlers();
                                while (
    $junhandlers=$juniors2->get_row()) { ?>
                                <option value="<?php echo $junhandlers['handler_id']?><?php if ($junhandlers['handler_id']==$main_handler_id) {echo 'selected';}?>><?php echo $junhandlers['handler_name'].' '.$junhandlers['handler_surname'];?></option>
                                <?php ?>
                                </select></td>
                                <td align="right">
                                <input type="checkbox" name="class_number[]" id="juniorclass" value="<?php echo $juniorrow['class_number']?>" /></td>
                              </tr>
                            <?php } } ?>
                            </table>
                          </div>
                          <?php } } if ($_SESSION['user_group_id']<3) { ?>
                              Entry Form: <input name="entry_form" type="text" class="fields" value="<?php echo $_SESSION['entry_form'];?>" size="6" />
                          <?php } else { ?>
                          <input type="hidden" name="entry_form" value="<?php echo $_SESSION['entry_form'];?>" />
                          <? ?>
                            <input name="Submit" type="submit" class="formbutt" id="Submit" value="Next" />
                        </form>
    The code that is used to process this part of the form is (this is from the Confirmation Page):
    PHP Code:
    <?php
                        $count_classes 
    count($_POST['class_number']);
                         
    $classes_form = (isset ($_POST['class_number'])) ? $_POST['class_number'] : array();
                         
    $handlers_form = (isset ($_POST['handler_id'])) ? $_POST['handler_id'] : array();
                        
                        
    $db = new database;
                        
    $db->connect();
                        
                        
    $handler=array_values(array_unique($handlers_form));
                        
                    foreach (
    $handler as $handlerID) {
                        
    $sql=pg_query("SELECT DISTINCT handler_id, handler_name, handler_surname
                                        FROM handlers
                                        WHERE handler_id=
    {$handlerID}");
                        
    $handlers=pg_fetch_array($sql);
                        echo 
    "<p><span class=\"infolabel\">Handler:</span> <strong>".$handlers['handler_name']." ".$handlers['handler_surname']."</strong></p><p><span class=\"infolabel\">Classes:</span>&nbsp;";
                        
    $handler_id=$handlers['handler_id'];
                        foreach (
    $classes_form as $classID) {
                            
    // If this class isn't being entered by the current handler, skip and move on to the next class
                            
    if ($handlers_form[$classID]!=$handlerID) continue;
                            
    $sql=pg_query("SELECT shows_classes.class_number, classes.class_id, classes.class_name, heights.height
                                            FROM shows_classes
                                            INNER JOIN classes ON shows_classes.class_id=classes.class_id 
                                            INNER JOIN heights ON heights.height_id=shows_classes.height_id
                                            WHERE shows_classes.show_id=
    {$_SESSION['show_id']} AND shows_classes.class_number={$classID} ORDER BY shows_classes.class_number");
                            
    $classes=pg_fetch_array($sql);
                            if (
    $classes['height']!='All') {
                            
    $classheight=$classes['height'];
                            }
                            else {
                            
    $classheight='';
                            }
                            echo 
    "<br /><span class=\"infolabel\">&nbsp;</span><span class=\"classnumber\">".$classes['class_number'].':</span>'.$classheight.' '.$classes['class_name'];
                            echo 
    '<input type="hidden" name="class_number['.$handler_id.'][]" value="'.$classes['class_number'].'" />';
                        }
                        echo 
    '</p>';
                    }

    ?>
    As a basis for what I need, this all works fine. However I really need to make some developments and improvements to both the form and the code on the confirmation page and I have been trying and trying but cannot work out how to get the various functions working that I need (bearing in mind that, even though I know this is not good, I am useless with arrays) and I am hoping that someone may be able to give me a few pointers on how I can maybe simplify the code and also get the extra functionality working. The main things I need to get working are:
    1. If a handler has no classes selected for them (i.e. a handler's name appears in the dropdown box next to a class in the form, but that class isn't selected), then I want to ensure that the handler's name doesn't get displayed on the confirmation page.
    2. Either on the page with the form, or as the form is submitted (whichever way will work best) I need to calculate how many classes have been selected for each day as sometimes there may be more listed than someone is allowed to select and this could vary each day.
    3. I need to prevent certain classes being selected if certain other ones have been selected as there may be restrictions to this effect that are applicable.
    4. If the Select All links are used and there is a limit to the number of classes that can be selected each day, that the first 'x-amount' of checkboxes are selected only.
    I really hope what I have provided makes sense as i never quite seem to get it right on these forums.
    Last edited by chilli11; Oct 3, 2007 at 07:56. Reason: Remembered something else


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •