Changeset 1503

Show
Ignore:
Timestamp:
12/12/2007 04:13:09 PM (13 months ago)
Author:
Shadowhand
Message:

Updated Form_Checklist with new syntax. Options are now defined as: $options = array($value => array($title, $checked)).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/forge/libraries/Form_Checklist.php

    r1502 r1503  
    55        protected $data = array 
    66        ( 
    7                 'name'  => '', 
    8                 'type'  => 'checkbox', 
    9                 'class' => 'checklist', 
     7                'name'    => '', 
     8                'type'    => 'checkbox', 
     9                'class'   => 'checklist', 
     10                'options' => array(), 
    1011        ); 
    1112 
     
    2223                { 
    2324                        // Return the currently checked values 
    24                         return array_keys($this->data['options'], TRUE); 
     25                        $array = array(); 
     26                        foreach($this->data['options'] as $id => $opt) 
     27                        { 
     28                                // Return the options that are checked 
     29                                ($opt[1] == TRUE) and $array[] = $id; 
     30                        } 
     31                        return $array; 
    2532                } 
    2633 
     
    4047 
    4148                $checklist = '<ul class="'.arr::remove('class', $base_data).'">'.$nl; 
    42                 foreach(arr::remove('options', $base_data) as $val => $checked) 
     49                foreach(arr::remove('options', $base_data) as $val => $opt) 
    4350                { 
    4451                        // New set of input data 
    4552                        $data = $base_data; 
     53 
     54                        // Get the title and checked status 
     55                        list ($title, $checked) = $opt; 
    4656 
    4757                        // Set the name, value, and checked status 
     
    4959                        $data['checked'] = $checked; 
    5060 
    51                         $checklist .= '<li><label>'.form::checkbox($data).' '.$val.'</label></li>'.$nl; 
     61                        $checklist .= '<li><label>'.form::checkbox($data).' '.$title.'</label></li>'.$nl; 
    5262                } 
    5363                $checklist .= '</ul>'; 
     
    6575                        if (empty($_POST[$this->data['name']])) 
    6676                        { 
    67                                 $this->data['options'][$val] = FALSE; 
     77                                $this->data['options'][$val][1] = FALSE; 
    6878                        } 
    6979                        else 
    7080                        { 
    71                                 $this->data['options'][$val] = in_array($val, $_POST[$this->data['name']]); 
     81                                $this->data['options'][$val][1] = in_array($val, $_POST[$this->data['name']]); 
    7282                        } 
    7383                }