Changeset 864

Show
Ignore:
Timestamp:
2007-09-18 22:16:19 (12 months ago)
Author:
freakerz
Message:

Updating FormUI to add <select> and <textarea>.

To define a selected option, use $select->selected= <id>; where <id> is the value="".

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/system/classes/formui.php

    r713 r864  
    411411        } 
    412412     
    413         $out= '<div class=' . $class . '>'; 
     413        $out= '<div class="' . $class . '">'; 
    414414        if(isset($message)) { 
    415415            $out.= "<p class=\"error\">{$message}</p>"; 
     
    475475} 
    476476 
     477/** 
     478 * A text control based on FormControl for output via a FormUI. 
     479 */ 
     480class FormControlSelect extends FormControl 
     481{ 
     482     
     483    public $selected; 
     484     
     485    /** 
     486     * Produce HTML output for this text control. 
     487     *  
     488     * @param boolean $forvalidation True if this control should render error information based on validation. 
     489     * @return string HTML that will render this control in the form 
     490     */ 
     491    public function out($forvalidation) 
     492    { 
     493        $class= 'select formcontrol'; 
     494        if($forvalidation) { 
     495            $validate= $this->validate(); 
     496            if(count($validate) != 0) { 
     497                $class.= ' invalid'; 
     498                $message= implode('<br>', $validate); 
     499            } 
     500        } 
     501 
     502        $out= '<div class="' . $class . '"><label>' . $this->caption . '<select name="' . $this->field . '">'; 
     503        foreach ( (array) $this->value as $key => $value ) { 
     504            $out.= '<option value="' . $key . '"' . ( ( $this->selected == $key ) ? ' selected' : '' ) . '>' . $value . '</option>'; 
     505        } 
     506        $out.= '</select></label>'; 
     507 
     508        if(isset($message)) { 
     509            $out.= "<p class=\"error\">{$message}</p>"; 
     510        } 
     511        $out.= '</div>'; 
     512 
     513        return $out; 
     514    } 
     515} 
     516 
     517/** 
     518 * A textarea control based on FormControl for output via a FormUI. 
     519 */ 
     520class FormControlTextArea extends FormControl 
     521{ 
     522 
     523    /** 
     524     * Produce HTML output for this text control. 
     525     *  
     526     * @param boolean $forvalidation True if this control should render error information based on validation. 
     527     * @return string HTML that will render this control in the form 
     528     */ 
     529    public function out($forvalidation) 
     530    { 
     531        $class= 'textarea formcontrol'; 
     532        if($forvalidation) { 
     533            $validate= $this->validate(); 
     534            if(count($validate) != 0) { 
     535                $class.= ' invalid'; 
     536                $message= implode('<br>', $validate); 
     537            } 
     538        } 
     539 
     540        $out= '<div class="' . $class . '"><label>' . $this->caption . '<textarea name="' . $this->field . '">' . $this->value . '</textarea></label>'; 
     541 
     542        if(isset($message)) { 
     543            $out.= "<p class=\"error\">{$message}</p>"; 
     544        } 
     545        $out.= '</div>'; 
     546 
     547        return $out; 
     548    } 
     549} 
     550 
     551 
    477552?>