Changeset 905

Show
Ignore:
Timestamp:
04/26/08 14:41:31 (7 months ago)
Author:
laurentj
Message:

fixed errors in unit tests on jforms htmlbuilder, because of changes by ticket #550
rewrote also parts of the htmlbuilder class to allow override it more easily

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

    r898 r905  
    149149 
    150150    public function outputControl($ctrl){ 
     151        if($ctrl->type == 'hidden') return; 
    151152        $id = ' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'"'; 
    152153        $class = ($ctrl->required == ''|| $ctrl->readonly?'':' jforms-required'); 
     
    155156        $readonly = ($ctrl->readonly?' readonly="readonly"':''); 
    156157        $hint = ($ctrl->hint == ''?'':' title="'.htmlspecialchars($ctrl->hint).'"'); 
    157         switch($ctrl->type){ 
    158         case 'input': 
    159             $value = $this->_form->getData($ctrl->ref); 
    160             $size = ($ctrl->size == 0?'' : ' size="'.$ctrl->size.'"'); 
    161             $maxl= $ctrl->datatype->getFacet('maxLength'); 
    162             if($maxl !== null) 
    163                 $maxl=' maxlength="'.$maxl.'"'; 
     158 
     159        $this->{'output'.$ctrl->type}($ctrl, $id, $class, $readonly, $hint); 
     160 
     161        $this->outputHelp($ctrl); 
     162    } 
     163 
     164    protected function outputInput($ctrl, $id, $class, $readonly, $hint) { 
     165        $value = $this->_form->getData($ctrl->ref); 
     166        $size = ($ctrl->size == 0?'' : ' size="'.$ctrl->size.'"'); 
     167        $maxl= $ctrl->datatype->getFacet('maxLength'); 
     168        if($maxl !== null) 
     169            $maxl=' maxlength="'.$maxl.'"'; 
     170        else 
     171            $maxl=''; 
     172        echo '<input type="text"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($value),'"',$this->_endt; 
     173    } 
     174 
     175    protected function outputCheckbox($ctrl, $id, $class, $readonly, $hint) { 
     176        $value = $this->_form->getData($ctrl->ref); 
     177 
     178        if($ctrl->valueOnCheck == $value){ 
     179            $v=' checked="checked"'; 
     180        }else{ 
     181            $v=''; 
     182        } 
     183        echo '<input type="checkbox"',$id,$readonly,$hint,$class,$v,' value="',$ctrl->valueOnCheck,'"',$this->_endt; 
     184    } 
     185 
     186    protected function outputCheckboxes($ctrl, $id, $class, $readonly, $hint) { 
     187        $i=0; 
     188        $id=$this->_name.'_'.$ctrl->ref.'_'; 
     189        $attrs=' name="'.$ctrl->ref.'[]" id="'.$id; 
     190        $value = $this->_form->getData($ctrl->ref); 
     191 
     192        if(is_array($value) && count($value) == 1) 
     193            $value = $value[0]; 
     194        $span ='<span class="jforms-chkbox jforms-ctl-'.$ctrl->ref.'"><input type="checkbox"'; 
     195 
     196        if(is_array($value)){ 
     197            foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     198                echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
     199                if(in_array($v,$value)) 
     200                    echo ' checked="checked"'; 
     201                echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
     202                $i++; 
     203            } 
     204        }else{ 
     205            foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     206                echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
     207                if($v == $value) 
     208                    echo ' checked="checked"'; 
     209                echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
     210                $i++; 
     211            } 
     212        } 
     213    } 
     214 
     215    protected function outputRadiobuttons($ctrl, $id, $class, $readonly, $hint) { 
     216        $i=0; 
     217        $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     218        $value = $this->_form->getData($ctrl->ref); 
     219        if(is_array($value)){ 
     220            if(isset($value[0])) 
     221                $value = $value[0]; 
    164222            else 
    165                 $maxl=''; 
    166             echo '<input type="text"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($value),'"',$this->_endt; 
    167             break; 
    168         case 'checkbox': 
    169             $value = $this->_form->getData($ctrl->ref); 
    170  
    171             if($ctrl->valueOnCheck == $value){ 
    172                 $v=' checked="checked"'; 
    173             }else{ 
    174                 $v=''; 
    175             } 
    176             echo '<input type="checkbox"',$id,$readonly,$hint,$class,$v,' value="',$ctrl->valueOnCheck,'"',$this->_endt; 
    177             break; 
    178         case 'checkboxes': 
    179             $i=0; 
    180             $id=$this->_name.'_'.$ctrl->ref.'_'; 
    181             $attrs=' name="'.$ctrl->ref.'[]" id="'.$id; 
     223                $value=''; 
     224        } 
     225        $span ='<span class="jforms-radio jforms-ctl-'.$ctrl->ref.'"><input type="radio"'; 
     226        foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     227            echo $span,$id,$i,'" value="',htmlspecialchars($v),'"',($v==$value?' checked="checked"':''),$readonly,$class,$this->_endt; 
     228            echo '<label for="',$this->_name,'_',$ctrl->ref,'_',$i,'">',htmlspecialchars($label),'</label></span>'; 
     229            $i++; 
     230        } 
     231    } 
     232 
     233    protected function outputMenulist($ctrl, $id, $class, $readonly, $hint) { 
     234        echo '<select',$id,$hint,$class,' size="1">'; 
     235        $value = $this->_form->getData($ctrl->ref); 
     236        if(is_array($value)){ 
     237            if(isset($value[0])) 
     238                $value = $value[0]; 
     239            else 
     240                $value=''; 
     241        } 
     242        if (!$ctrl->required) { 
     243            echo '<option value=""',($value==''?' selected="selected"':''),'></option>'; 
     244        } 
     245        foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     246            echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     247        } 
     248        echo '</select>'; 
     249    } 
     250 
     251    protected function outputListbox($ctrl, $id, $class, $readonly, $hint) { 
     252        if($ctrl->multiple){ 
     253            echo '<select name="',$ctrl->ref,'[]" id="',$this->_name,'_',$ctrl->ref,'"',$hint,$class,' size="',$ctrl->size,'" multiple="multiple">'; 
    182254            $value = $this->_form->getData($ctrl->ref); 
    183255 
    184256            if(is_array($value) && count($value) == 1) 
    185257                $value = $value[0]; 
    186             $span ='<span class="jforms-chkbox jforms-ctl-'.$ctrl->ref.'"><input type="checkbox"'; 
    187258 
    188259            if(is_array($value)){ 
    189260                foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    190                     echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
    191                     if(in_array($v,$value)) 
    192                         echo ' checked="checked"'; 
    193                     echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
    194                     $i++; 
     261                    echo '<option value="',htmlspecialchars($v),'"',(in_array($v,$value)?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    195262                } 
    196263            }else{ 
    197264                foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    198                     echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
    199                     if($v == $value) 
    200                         echo ' checked="checked"'; 
    201                     echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
    202                     $i++; 
    203                 } 
    204             } 
    205             break; 
    206         case 'radiobuttons': 
    207             $i=0; 
    208             $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     265                    echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     266                } 
     267            } 
     268            echo '</select>'; 
     269        }else{ 
    209270            $value = $this->_form->getData($ctrl->ref); 
     271 
    210272            if(is_array($value)){ 
    211                 if(isset($value[0])
     273                if(count($value) >= 1
    212274                    $value = $value[0]; 
    213275                else 
    214                     $value=''; 
    215             } 
    216             $span ='<span class="jforms-radio jforms-ctl-'.$ctrl->ref.'"><input type="radio"'; 
    217             foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    218                 echo $span,$id,$i,'" value="',htmlspecialchars($v),'"',($v==$value?' checked="checked"':''),$readonly,$class,$this->_endt; 
    219                 echo '<label for="',$this->_name,'_',$ctrl->ref,'_',$i,'">',htmlspecialchars($label),'</label></span>'; 
    220                 $i++; 
    221             } 
    222             break; 
    223         case 'menulist': 
    224             echo '<select',$id,$hint,$class,' size="1">'; 
    225             $value = $this->_form->getData($ctrl->ref); 
    226             if(is_array($value)){ 
    227                 if(isset($value[0])) 
    228                     $value = $value[0]; 
    229                 else 
    230                     $value=''; 
    231             } 
    232             if (!$ctrl->required) { 
    233                 echo '<option value=""',($value==''?' selected="selected"':''),'></option>'; 
    234             } 
     276                    $value =''; 
     277            } 
     278 
     279            echo '<select',$id,$hint,$class,' size="',$ctrl->size,'">'; 
    235280            foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    236281                echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    237282            } 
    238283            echo '</select>'; 
    239             break; 
    240         case 'listbox': 
    241             if($ctrl->multiple){ 
    242                 echo '<select name="',$ctrl->ref,'[]" id="',$this->_name,'_',$ctrl->ref,'"',$hint,$class,' size="',$ctrl->size,'" multiple="multiple">'; 
    243                 $value = $this->_form->getData($ctrl->ref); 
    244  
    245                 if(is_array($value) && count($value) == 1) 
    246                     $value = $value[0]; 
    247  
    248                 if(is_array($value)){ 
    249                     foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    250                         echo '<option value="',htmlspecialchars($v),'"',(in_array($v,$value)?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    251                     } 
    252                 }else{ 
    253                     foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    254                         echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    255                     } 
    256                 } 
    257                 echo '</select>'; 
    258             }else{ 
    259                 $value = $this->_form->getData($ctrl->ref); 
    260  
    261                 if(is_array($value)){ 
    262                     if(count($value) >= 1) 
    263                         $value = $value[0]; 
    264                     else 
    265                         $value =''; 
    266                 } 
    267  
    268                 echo '<select',$id,$hint,$class,' size="',$ctrl->size,'">'; 
    269                 foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    270                     echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    271                 } 
    272                 echo '</select>'; 
    273             } 
    274             break; 
    275         case 'textarea': 
    276             $value = $this->_form->getData($ctrl->ref); 
    277             $rows = ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"'; 
    278             echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>'; 
    279             break; 
    280         case 'htmleditor': 
    281             $engine = $GLOBALS['gJConfig']->htmleditors[$ctrl->config.'.engine.name']; 
    282             echo '<script type="text/javascript"> 
    283             //<![CDATA[ 
    284             jelix_',$engine,'_',$ctrl->config.'("',$this->_name,'_',$ctrl->ref,'","',$this->_name,'"); 
    285             //]]> 
    286             </script>'; 
    287  
    288             $value = $this->_form->getData($ctrl->ref); 
    289             $rows = ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"'; 
    290             echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>'; 
    291             break; 
    292         case 'secret': 
    293         case 'secretconfirm': 
    294             $size = ($ctrl->size == 0?'': ' size="'.$ctrl->size.'"'); 
    295             echo '<input type="password"',$id,$readonly,$hint,$class,$size,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt; 
    296             break; 
    297         case 'output': 
     284        } 
     285    } 
     286 
     287    protected function outputTextarea($ctrl, $id, $class, $readonly, $hint) { 
     288        $value = $this->_form->getData($ctrl->ref); 
     289        $rows = ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"'; 
     290        echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>'; 
     291    } 
     292 
     293    protected function outputHtmleditor($ctrl, $id, $class, $readonly, $hint) { 
     294        $engine = $GLOBALS['gJConfig']->htmleditors[$ctrl->config.'.engine.name']; 
     295        echo '<script type="text/javascript"> 
     296//<![CDATA[ 
     297jelix_',$engine,'_',$ctrl->config.'("',$this->_name,'_',$ctrl->ref,'","',$this->_name,'"); 
     298//]]> 
     299</script>'; 
     300 
     301        $value = $this->_form->getData($ctrl->ref); 
     302        $rows = ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"'; 
     303        echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>'; 
     304    } 
     305 
     306    protected function outputSecret($ctrl, $id, $class, $readonly, $hint) { 
     307        $size = ($ctrl->size == 0?'': ' size="'.$ctrl->size.'"'); 
     308        echo '<input type="password"',$id,$readonly,$hint,$class,$size,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt; 
     309    } 
     310 
     311    protected function outputSecretconfirm($ctrl, $id, $class, $readonly, $hint) { 
     312        $size = ($ctrl->size == 0?'': ' size="'.$ctrl->size.'"'); 
     313        echo '<input type="password"',$id,$readonly,$hint,$class,$size,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt; 
     314    } 
     315 
     316    protected function outputOutput($ctrl, $id, $class, $readonly, $hint) { 
    298317            $value = $this->_form->getData($ctrl->ref); 
    299318            echo '<input type="hidden"',$id,' value="',htmlspecialchars($value),'"',$this->_endt; 
    300319            echo '<span class="jforms-value"',$hint,'>',htmlspecialchars($value),'</span>'; 
    301             break; 
    302         case 'upload': 
     320    } 
     321 
     322    protected function outputUpload($ctrl, $id, $class, $readonly, $hint) { 
    303323            if($ctrl->maxsize){ 
    304324                echo '<input type="hidden" name="MAX_FILE_SIZE" value="',$ctrl->maxsize,'"',$this->_endt; 
    305325            } 
    306326            echo '<input type="file"',$id,$readonly,$hint,$class,' value=""',$this->_endt; // ',htmlspecialchars($this->_form->getData($ctrl->ref)),' 
    307             break; 
    308         case 'submit': 
     327 
     328    } 
     329 
     330    protected function outputSubmit($ctrl, $id, $class, $readonly, $hint) { 
    309331            if($ctrl->standalone){ 
    310332                echo '<input type="submit"',$id,$hint,' class="jforms-submit" value="',htmlspecialchars($ctrl->label),'"/>'; 
     
    316338                } 
    317339            } 
    318             break; 
    319         case 'reset': 
    320             echo '<button type="reset"',$id,$hint,' class="jforms-reset">',htmlspecialchars($ctrl->label),'</button>'; 
    321             break; 
    322         case 'captcha': 
    323             $ctrl->initExpectedValue($this->_form); 
    324             echo '<span class="jforms-captcha-question">',htmlspecialchars($ctrl->question),'</span> '; 
    325             echo '<input type="text"',$id,$hint,$class,' value=""',$this->_endt; 
    326             break; 
    327         } 
    328  
     340    } 
     341 
     342    protected function outputReset($ctrl, $id, $class, $readonly, $hint) { 
     343        echo '<button type="reset"',$id,$hint,' class="jforms-reset">',htmlspecialchars($ctrl->label),'</button>'; 
     344    } 
     345 
     346    protected function outputCaptcha($ctrl, $id, $class, $readonly, $hint) { 
     347        $ctrl->initExpectedValue($this->_form); 
     348        echo '<span class="jforms-captcha-question">',htmlspecialchars($ctrl->question),'</span> '; 
     349        echo '<input type="text"',$id,$hint,$class,' value=""',$this->_endt; 
     350    } 
     351 
     352    protected function outputHelp($ctrl) { 
    329353        if ($ctrl->hasHelp) { 
    330354            if($ctrl->type == 'checkboxes' || ($ctrl->type == 'listbox' && $ctrl->multiple)){ 
  • trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

    r898 r905  
    149149 
    150150    public function outputControl($ctrl){ 
     151        if($ctrl->type == 'hidden') return; 
    151152        $id = ' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'"'; 
    152153        $class = ($ctrl->required == ''|| $ctrl->readonly?'':' jforms-required'); 
     
    155156        $readonly = ($ctrl->readonly?' readonly="readonly"':''); 
    156157        $hint = ($ctrl->hint == ''?'':' title="'.htmlspecialchars($ctrl->hint).'"'); 
    157         switch($ctrl->type){ 
    158         case 'input': 
    159             $value = $this->_form->getData($ctrl->ref); 
    160             $size = ($ctrl->size == 0?'' : ' size="'.$ctrl->size.'"'); 
    161             $maxl= $ctrl->datatype->getFacet('maxLength'); 
    162             if($maxl !== null) 
    163                 $maxl=' maxlength="'.$maxl.'"'; 
     158 
     159        $this->{'output'.$ctrl->type}($ctrl, $id, $class, $readonly, $hint); 
     160 
     161        $this->outputHelp($ctrl); 
     162    } 
     163 
     164    protected function outputInput($ctrl, $id, $class, $readonly, $hint) { 
     165        $value = $this->_form->getData($ctrl->ref); 
     166        $size = ($ctrl->size == 0?'' : ' size="'.$ctrl->size.'"'); 
     167        $maxl= $ctrl->datatype->getFacet('maxLength'); 
     168        if($maxl !== null) 
     169            $maxl=' maxlength="'.$maxl.'"'; 
     170        else 
     171            $maxl=''; 
     172        echo '<input type="text"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($value),'"',$this->_endt; 
     173    } 
     174 
     175    protected function outputCheckbox($ctrl, $id, $class, $readonly, $hint) { 
     176        $value = $this->_form->getData($ctrl->ref); 
     177 
     178        if($ctrl->valueOnCheck == $value){ 
     179            $v=' checked="checked"'; 
     180        }else{ 
     181            $v=''; 
     182        } 
     183        echo '<input type="checkbox"',$id,$readonly,$hint,$class,$v,' value="',$ctrl->valueOnCheck,'"',$this->_endt; 
     184    } 
     185 
     186    protected function outputCheckboxes($ctrl, $id, $class, $readonly, $hint) { 
     187        $i=0; 
     188        $id=$this->_name.'_'.$ctrl->ref.'_'; 
     189        $attrs=' name="'.$ctrl->ref.'[]" id="'.$id; 
     190        $value = $this->_form->getData($ctrl->ref); 
     191 
     192        if(is_array($value) && count($value) == 1) 
     193            $value = $value[0]; 
     194        $span ='<span class="jforms-chkbox jforms-ctl-'.$ctrl->ref.'"><input type="checkbox"'; 
     195 
     196        if(is_array($value)){ 
     197            foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     198                echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
     199                if(in_array($v,$value)) 
     200                    echo ' checked="checked"'; 
     201                echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
     202                $i++; 
     203            } 
     204        }else{ 
     205            foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     206                echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
     207                if($v == $value) 
     208                    echo ' checked="checked"'; 
     209                echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
     210                $i++; 
     211            } 
     212        } 
     213    } 
     214 
     215    protected function outputRadiobuttons($ctrl, $id, $class, $readonly, $hint) { 
     216        $i=0; 
     217        $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     218        $value = $this->_form->getData($ctrl->ref); 
     219        if(is_array($value)){ 
     220            if(isset($value[0])) 
     221                $value = $value[0]; 
    164222            else 
    165                 $maxl=''; 
    166             echo '<input type="text"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($value),'"',$this->_endt; 
    167             break; 
    168         case 'checkbox': 
    169             $value = $this->_form->getData($ctrl->ref); 
    170  
    171             if($ctrl->valueOnCheck == $value){ 
    172                 $v=' checked="checked"'; 
    173             }else{ 
    174                 $v=''; 
    175             } 
    176             echo '<input type="checkbox"',$id,$readonly,$hint,$class,$v,' value="',$ctrl->valueOnCheck,'"',$this->_endt; 
    177             break; 
    178         case 'checkboxes': 
    179             $i=0; 
    180             $id=$this->_name.'_'.$ctrl->ref.'_'; 
    181             $attrs=' name="'.$ctrl->ref.'[]" id="'.$id; 
     223                $value=''; 
     224        } 
     225        $span ='<span class="jforms-radio jforms-ctl-'.$ctrl->ref.'"><input type="radio"'; 
     226        foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     227            echo $span,$id,$i,'" value="',htmlspecialchars($v),'"',($v==$value?' checked="checked"':''),$readonly,$class,$this->_endt; 
     228            echo '<label for="',$this->_name,'_',$ctrl->ref,'_',$i,'">',htmlspecialchars($label),'</label></span>'; 
     229            $i++; 
     230        } 
     231    } 
     232 
     233    protected function outputMenulist($ctrl, $id, $class, $readonly, $hint) { 
     234        echo '<select',$id,$hint,$class,' size="1">'; 
     235        $value = $this->_form->getData($ctrl->ref); 
     236        if(is_array($value)){ 
     237            if(isset($value[0])) 
     238                $value = $value[0]; 
     239            else 
     240                $value=''; 
     241        } 
     242        if (!$ctrl->required) { 
     243            echo '<option value=""',($value==''?' selected="selected"':''),'></option>'; 
     244        } 
     245        foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     246            echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     247        } 
     248        echo '</select>'; 
     249    } 
     250 
     251    protected function outputListbox($ctrl, $id, $class, $readonly, $hint) { 
     252        if($ctrl->multiple){ 
     253            echo '<select name="',$ctrl->ref,'[]" id="',$this->_name,'_',$ctrl->ref,'"',$hint,$class,' size="',$ctrl->size,'" multiple="multiple">'; 
    182254            $value = $this->_form->getData($ctrl->ref); 
    183255 
    184256            if(is_array($value) && count($value) == 1) 
    185257                $value = $value[0]; 
    186             $span ='<span class="jforms-chkbox jforms-ctl-'.$ctrl->ref.'"><input type="checkbox"'; 
    187258 
    188259            if(is_array($value)){ 
    189260                foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    190                     echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
    191                     if(in_array($v,$value)) 
    192                         echo ' checked="checked"'; 
    193                     echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
    194                     $i++; 
     261                    echo '<option value="',htmlspecialchars($v),'"',(in_array($v,$value)?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    195262                } 
    196263            }else{ 
    197264                foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    198                     echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
    199                     if($v == $value) 
    200                         echo ' checked="checked"'; 
    201                     echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
    202                     $i++; 
    203                 } 
    204             } 
    205             break; 
    206         case 'radiobuttons': 
    207             $i=0; 
    208             $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     265                    echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     266                } 
     267            } 
     268            echo '</select>'; 
     269        }else{ 
    209270            $value = $this->_form->getData($ctrl->ref); 
     271 
    210272            if(is_array($value)){ 
    211                 if(isset($value[0])
     273                if(count($value) >= 1
    212274                    $value = $value[0]; 
    213275                else 
    214                     $value=''; 
    215             } 
    216             $span ='<span class="jforms-radio jforms-ctl-'.$ctrl->ref.'"><input type="radio"'; 
    217             foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    218                 echo $span,$id,$i,'" value="',htmlspecialchars($v),'"',($v==$value?' checked="checked"':''),$readonly,$class,$this->_endt; 
    219                 echo '<label for="',$this->_name,'_',$ctrl->ref,'_',$i,'">',htmlspecialchars($label),'</label></span>'; 
    220                 $i++; 
    221             } 
    222             break; 
    223         case 'menulist': 
    224             echo '<select',$id,$hint,$class,' size="1">'; 
    225             $value = $this->_form->getData($ctrl->ref); 
    226             if(is_array($value)){ 
    227                 if(isset($value[0])) 
    228                     $value = $value[0]; 
    229                 else 
    230                     $value=''; 
    231             } 
    232             if (!$ctrl->required) { 
    233                 echo '<option value=""',($value==''?' selected="selected"':''),'></option>'; 
    234             } 
     276                    $value =''; 
     277            } 
     278 
     279            echo '<select',$id,$hint,$class,' size="',$ctrl->size,'">'; 
    235280            foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    236281                echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    237282            } 
    238283            echo '</select>'; 
    239             break; 
    240         case 'listbox': 
    241             if($ctrl->multiple){ 
    242                 echo '<select name="',$ctrl->ref,'[]" id="',$this->_name,'_',$ctrl->ref,'"',$hint,$class,' size="',$ctrl->size,'" multiple="multiple">'; 
    243                 $value = $this->_form->getData($ctrl->ref); 
    244  
    245                 if(is_array($value) && count($value) == 1) 
    246                     $value = $value[0]; 
    247  
    248                 if(is_array($value)){ 
    249                     foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    250                         echo '<option value="',htmlspecialchars($v),'"',(in_array($v,$value)?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    251                     } 
    252                 }else{ 
    253                     foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    254                         echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    255                     } 
    256                 } 
    257                 echo '</select>'; 
    258             }else{ 
    259                 $value = $this->_form->getData($ctrl->ref); 
    260  
    261                 if(is_array($value)){ 
    262                     if(count($value) >= 1) 
    263                         $value = $value[0]; 
    264                     else 
    265                         $value =''; 
    266                 } 
    267  
    268                 echo '<select',$id,$hint,$class,' size="',$ctrl->size,'">'; 
    269                 foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    270                     echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    271                 } 
    272                 echo '</select>'; 
    273             } 
    274             break; 
    275         case 'textarea': 
    276             $value = $this->_form->getData($ctrl->ref); 
    277             $rows = ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"'; 
    278             echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>'; 
    279             break; 
    280         case 'htmleditor': 
    281             $engine = $GLOBALS['gJConfig']->htmleditors[$ctrl->config.'.engine.name']; 
    282             echo '<script type="text/javascript"> 
    283             //<![CDATA[ 
    284             jelix_',$engine,'_',$ctrl->config.'("',$this->_name,'_',$ctrl->ref,'","',$this->_name,'"); 
    285             //]]> 
    286             </script>'; 
    287  
    288             $value = $this->_form->getData($ctrl->ref); 
    289             $rows = ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"'; 
    290             echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>'; 
    291             break; 
    292         case 'secret': 
    293         case 'secretconfirm': 
    294             $size = ($ctrl->size == 0?'': ' size="'.$ctrl->size.'"'); 
    295             echo '<input type="password"',$id,$readonly,$hint,$class,$size,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt; 
    296             break; 
    297         case 'output': 
     284        } 
     285    } 
     286 
     287    protected function outputTextarea($ctrl, $id, $class, $readonly, $hint) { 
     288        $value = $this->_form->getData($ctrl->ref); 
     289        $rows = ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"'; 
     290        echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>'; 
     291    } 
     292 
     293    protected function outputHtmleditor($ctrl, $id, $class, $readonly, $hint) { 
     294        $engine = $GLOBALS['gJConfig']->htmleditors[$ctrl->config.'.engine.name']; 
     295        echo '<script type="text/javascript"> 
     296//<![CDATA[ 
     297jelix_',$engine,'_',$ctrl->config.'("',$this->_name,'_',$ctrl->ref,'","',$this->_name,'"); 
     298//]]> 
     299</script>'; 
     300 
     301        $value = $this->_form->getData($ctrl->ref); 
     302        $rows = ' rows="'.$ctrl->rows.'" cols="'.$ctrl->cols.'"'; 
     303        echo '<textarea',$id,$readonly,$hint,$class,$rows,'>',htmlspecialchars($value),'</textarea>'; 
     304    } 
     305 
     306    protected function outputSecret($ctrl, $id, $class, $readonly, $hint) { 
     307        $size = ($ctrl->size == 0?'': ' size="'.$ctrl->size.'"'); 
     308        echo '<input type="password"',$id,$readonly,$hint,$class,$size,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt; 
     309    } 
     310 
     311    protected function outputSecretconfirm($ctrl, $id, $class, $readonly, $hint) { 
     312        $size = ($ctrl->size == 0?'': ' size="'.$ctrl->size.'"'); 
     313        echo '<input type="password"',$id,$readonly,$hint,$class,$size,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"',$this->_endt; 
     314    } 
     315 
     316    protected function outputOutput($ctrl, $id, $class, $readonly, $hint) { 
    298317            $value = $this->_form->getData($ctrl->ref); 
    299318            echo '<input type="hidden"',$id,' value="',htmlspecialchars($value),'"',$this->_endt; 
    300319            echo '<span class="jforms-value"',$hint,'>',htmlspecialchars($value),'</span>'; 
    301             break; 
    302         case 'upload': 
     320    } 
     321 
     322    protected function outputUpload($ctrl, $id, $class, $readonly, $hint) { 
    303323            if($ctrl->maxsize){ 
    304324                echo '<input type="hidden" name="MAX_FILE_SIZE" value="',$ctrl->maxsize,'"',$this->_endt; 
    305325            } 
    306326            echo '<input type="file"',$id,$readonly,$hint,$class,' value=""',$this->_endt; // ',htmlspecialchars($this->_form->getData($ctrl->ref)),' 
    307             break; 
    308         case 'submit': 
     327 
     328    } 
     329 
     330    protected function outputSubmit($ctrl, $id, $class, $readonly, $hint) { 
    309331            if($ctrl->standalone){ 
    310332                echo '<input type="submit"',$id,$hint,' class="jforms-submit" value="',htmlspecialchars($ctrl->label),'"/>'; 
     
    316338                } 
    317339            } 
    318             break; 
    319         case 'reset': 
    320             echo '<button type="reset"',$id,$hint,' class="jforms-reset">',htmlspecialchars($ctrl->label),'</button>'; 
    321             break; 
    322         case 'captcha': 
    323             $ctrl->initExpectedValue($this->_form); 
    324             echo '<span class="jforms-captcha-question">',htmlspecialchars($ctrl->question),'</span> '; 
    325             echo '<input type="text"',$id,$hint,$class,' value=""',$this->_endt; 
    326             break; 
    327         } 
    328  
     340    } 
     341 
     342    protected function outputReset($ctrl, $id, $class, $readonly, $hint) { 
     343        echo '<button type="reset"',$id,$hint,' class="jforms-reset">',htmlspecialchars($ctrl->label),'</button>'; 
     344    } 
     345 
     346    protected function outputCaptcha($ctrl, $id, $class, $readonly, $hint) { 
     347        $ctrl->initExpectedValue($this->_form); 
     348        echo '<span class="jforms-captcha-question">',htmlspecialchars($ctrl->question),'</span> '; 
     349        echo '<input type="text"',$id,$hint,$class,' value=""',$this->_endt; 
     350    } 
     351 
     352    protected function outputHelp($ctrl) { 
    329353        if ($ctrl->hasHelp) { 
    330354            if($ctrl->type == 'checkboxes' || ($ctrl->type == 'listbox' && $ctrl->multiple)){ 
  • trunk/lib/jelix/plugins/jforms/html/html.jformsbuilder.php

    r898 r905  
    149149 
    150150    public function outputControl($ctrl){ 
     151        if($ctrl->type == 'hidden') return; 
    151152        $id = ' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'"'; 
    152153        $class = ($ctrl->required == ''|| $ctrl->readonly?'':' jforms-required'); 
     
    155156        $readonly = ($ctrl->readonly?' readonly="readonly"':''); 
    156157        $hint = ($ctrl->hint == ''?'':' title="'.htmlspecialchars($ctrl->hint).'"'); 
    157         switch($ctrl->type){ 
    158         case 'input': 
    159             $value = $this->_form->getData($ctrl->ref); 
    160             $size = ($ctrl->size == 0?'' : ' size="'.$ctrl->size.'"'); 
    161             $maxl= $ctrl->datatype->getFacet('maxLength'); 
    162             if($maxl !== null) 
    163                 $maxl=' maxlength="'.$maxl.'"'; 
     158 
     159        $this->{'output'.$ctrl->type}($ctrl, $id, $class, $readonly, $hint); 
     160 
     161        $this->outputHelp($ctrl); 
     162    } 
     163 
     164    protected function outputInput($ctrl, $id, $class, $readonly, $hint) { 
     165        $value = $this->_form->getData($ctrl->ref); 
     166        $size = ($ctrl->size == 0?'' : ' size="'.$ctrl->size.'"'); 
     167        $maxl= $ctrl->datatype->getFacet('maxLength'); 
     168        if($maxl !== null) 
     169            $maxl=' maxlength="'.$maxl.'"'; 
     170        else 
     171            $maxl=''; 
     172        echo '<input type="text"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($value),'"',$this->_endt; 
     173    } 
     174 
     175    protected function outputCheckbox($ctrl, $id, $class, $readonly, $hint) { 
     176        $value = $this->_form->getData($ctrl->ref); 
     177 
     178        if($ctrl->valueOnCheck == $value){ 
     179            $v=' checked="checked"'; 
     180        }else{ 
     181            $v=''; 
     182        } 
     183        echo '<input type="checkbox"',$id,$readonly,$hint,$class,$v,' value="',$ctrl->valueOnCheck,'"',$this->_endt; 
     184    } 
     185 
     186    protected function outputCheckboxes($ctrl, $id, $class, $readonly, $hint) { 
     187        $i=0; 
     188        $id=$this->_name.'_'.$ctrl->ref.'_'; 
     189        $attrs=' name="'.$ctrl->ref.'[]" id="'.$id; 
     190        $value = $this->_form->getData($ctrl->ref); 
     191 
     192        if(is_array($value) && count($value) == 1) 
     193            $value = $value[0]; 
     194        $span ='<span class="jforms-chkbox jforms-ctl-'.$ctrl->ref.'"><input type="checkbox"'; 
     195 
     196        if(is_array($value)){ 
     197            foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     198                echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
     199                if(in_array($v,$value)) 
     200                    echo ' checked="checked"'; 
     201                echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
     202                $i++; 
     203            } 
     204        }else{ 
     205            foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     206                echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
     207                if($v == $value) 
     208                    echo ' checked="checked"'; 
     209                echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
     210                $i++; 
     211            } 
     212        } 
     213    } 
     214 
     215    protected function outputRadiobuttons($ctrl, $id, $class, $readonly, $hint) { 
     216        $i=0; 
     217        $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     218        $value = $this->_form->getData($ctrl->ref); 
     219        if(is_array($value)){ 
     220            if(isset($value[0])) 
     221                $value = $value[0]; 
    164222            else 
    165                 $maxl=''; 
    166             echo '<input type="text"',$id,$readonly,$hint,$class,$size,$maxl,' value="',htmlspecialchars($value),'"',$this->_endt; 
    167             break; 
    168         case 'checkbox': 
    169             $value = $this->_form->getData($ctrl->ref); 
    170  
    171             if($ctrl->valueOnCheck == $value){ 
    172                 $v=' checked="checked"'; 
    173             }else{ 
    174                 $v=''; 
    175             } 
    176             echo '<input type="checkbox"',$id,$readonly,$hint,$class,$v,' value="',$ctrl->valueOnCheck,'"',$this->_endt; 
    177             break; 
    178         case 'checkboxes': 
    179             $i=0; 
    180             $id=$this->_name.'_'.$ctrl->ref.'_'; 
    181             $attrs=' name="'.$ctrl->ref.'[]" id="'.$id; 
     223                $value=''; 
     224        } 
     225        $span ='<span class="jforms-radio jforms-ctl-'.$ctrl->ref.'"><input type="radio"'; 
     226        foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     227            echo $span,$id,$i,'" value="',htmlspecialchars($v),'"',($v==$value?' checked="checked"':''),$readonly,$class,$this->_endt; 
     228            echo '<label for="',$this->_name,'_',$ctrl->ref,'_',$i,'">',htmlspecialchars($label),'</label></span>'; 
     229            $i++; 
     230        } 
     231    } 
     232 
     233    protected function outputMenulist($ctrl, $id, $class, $readonly, $hint) { 
     234        echo '<select',$id,$hint,$class,' size="1">'; 
     235        $value = $this->_form->getData($ctrl->ref); 
     236        if(is_array($value)){ 
     237            if(isset($value[0])) 
     238                $value = $value[0]; 
     239            else 
     240                $value=''; 
     241        } 
     242        if (!$ctrl->required) { 
     243            echo '<option value=""',($value==''?' selected="selected"':''),'></option>'; 
     244        } 
     245        foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
     246            echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     247        } 
     248        echo '</select>'; 
     249    } 
     250 
     251    protected function outputListbox($ctrl, $id, $class, $readonly, $hint) { 
     252        if($ctrl->multiple){ 
     253            echo '<select name="',$ctrl->ref,'[]" id="',$this->_name,'_',$ctrl->ref,'"',$hint,$class,' size="',$ctrl->size,'" multiple="multiple">'; 
    182254            $value = $this->_form->getData($ctrl->ref); 
    183255 
    184256            if(is_array($value) && count($value) == 1) 
    185257                $value = $value[0]; 
    186             $span ='<span class="jforms-chkbox jforms-ctl-'.$ctrl->ref.'"><input type="checkbox"'; 
    187258 
    188259            if(is_array($value)){ 
    189260                foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    190                     echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
    191                     if(in_array($v,$value)) 
    192                         echo ' checked="checked"'; 
    193                     echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
    194                     $i++; 
     261                    echo '<option value="',htmlspecialchars($v),'"',(in_array($v,$value)?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
    195262                } 
    196263            }else{ 
    197264                foreach($ctrl->datasource->getData($this->_form) as $v=>$label){ 
    198                     echo $span,$attrs,$i,'" value="',htmlspecialchars($v),'"'; 
    199                     if($v == $value) 
    200                         echo ' checked="checked"'; 
    201                     echo $readonly,$class,$this->_endt,'<label for="',$id,$i,'">',htmlspecialchars($label),'</label></span>'; 
    202                     $i++; 
    203                 } 
    204             } 
    205             break; 
    206         case 'radiobuttons': 
    207             $i=0; 
    208             $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     265                    echo '<option value="',htmlspecialchars($v),'"',($v==$value?' selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     266                } 
     267            } 
     268            echo '</select>'; 
     269        }else{ 
    209270            $value = $this->_form->getData($ctrl->ref); 
     271 
    210272            if(is_array($value)){ 
    211                 if(isset($value[0])
     273                if(count($value) >= 1
    212274                    $value = $value[0]; 
    213275                else 
    214                     $value=''; 
    215             } 
    216             $span ='<span class="jforms-radio jforms-ctl-'.$ctrl->ref.'"><input type="radio"'; 
    217             foreach($ctrl->datasource->getData($this->_