Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Form  /  Select   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tl.gif Base tr.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tls.gif     Form  trs.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tl.gif Mvc tr.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tl.gif Table tr.gif tl.gif Util tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Select.php


Vis: Sample code, tutorial

Select, Sample code, tutorial

Sådan benyttes komponenten Select klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Select.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Select
    ::display($param1$param2$param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object 
    = new Select($param1$param2$param3, ...);
    print 
    $object->getHtml();
    ?>

Skjul: Sådan vises komponenten

Select, Sådan vises komponenten

Sådan vises komponenten Select klassen



Vis: PHP source code

Select, PHP source code

Den fulde PHP kildekode for Select klassen

<?php
/**
 * @package form
 * @filesource
 * @see HTML_FORM_COMPONENT_PATH.'/Select.php'
 * @copyright (c) http://Finn-Rasmussen.com
 * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
 * @author http://Finn-Rasmussen.com
 * @version 1.11
 * @since 27-nov-2009
 */

/**
 * The required files
 */
require_once(HTML_BASE_UTIL_PATH.'/Element.php');
require_once(
HTML_BASE_UTIL_PATH.'/Tabindex.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Options.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Option.php');

/**
 * Generates a SELECT form element 
 * <code>
 * Usage:
 *   $text  = 'option text';
 *   $value = 'option value';
 *   // An array of option elements
 *   $optionArray = array(
 *      array('text'=>'option 1','value'=>'1','selected'=>'','title'=>'','label'=>''), 
 *      array('text'=>'option 2','value'=>'2','selected'=>'selected','title'=>'','label'=>''), 
 *      array('text'=>'option 3','value'=>'3','selected'=>'','title'=>'','label'=>''), 
 *   );
 *   $options = new Options($optionArray, $name);
 *   $select = new Select($name, $class, $onchange, $multiple, $size, $disabled,'', $title, $tabindex);
 *   $select->add(new Option($value, $value)); // One or more single option elements
 *      :               :
 *   print $select->getHtml();
 * OR
 *   $select = new Select($name, $class, $onchange, $multiple, $size, $disabled, $options, $title, $tabindex);
 *   print $select->getHtml();
 * OR
 *   $select = new Select($name, $class, $onchange, $multiple, $size, $disabled,'', $title, $tabindex);
 *   $select->add(new Options($optionArray, $name)); // An array of option elements
 *   print $select->getHtml();
 * OR
 *   Select::start($name, $class, $onchange, $multiple, $size, $disabled,'', $title, $tabindex);
 *   Option::display($value, $value); // One or more single option elements
 *      :            :
 *   Select::end();
 * OR
 *   Select::start($name, $class, $onchange, $multiple, $size, $disabled,'', $title, $tabindex);
 *   Options::display($optionArray, $name); // An array of option elements
 *      :            :
 *   Select::end();
 * OR
 *   Select::display($name, $class, $onchange, $multiple, $size, $disabled, $options, $title, $tabindex);
 * </code>
 * @package form
 */

class Select extends Element {
    
/**
     * @var String $onchange The On change event
     */
    
protected $onchange ''

    
/**
     * @var String $multiple The multiple select attribute
     */
    
protected $multiple ''

    
/**
     * @var String $size The size
     */
    
protected $size ''

    
/**
     * @var String $disabled The disabled (>IE4.x)
     */
    
protected $disabled  ''

    
/**
     * @var Options $options The new options object
     */
    
protected $options  ''

    
/**
     * Constructor
     * @param String $name      The name of the control
     * @param String $class     The class name
     * @param String $onchange  On Change Event name i.e. 'EMNE'
     * @param String $multiple  The multiple attribute
     * @param String $size      The size attribute
     * @param String $disabled  The disabled
     * @param String $options   The new options object, if present
     * @param String $title     The tooltip
     * @param String $tabindex  The tabindex
     * @param String $accesskey The accesskey
     */
    
function __construct($name=''$class=''$onchange=''$multiple=''$size=''$disabled=''$options=''$title=''$tabindex='') {
        
$aClass    $class != ''?$class:CSS_SELECT_CLASS;
        
$value     ''// Not for a Select
        
$accesskey ''// Not for a Select
        
$aTabindex $tabindex != ''?$tabindex:Tabindex::next();
        
$onclick ''// Not used
        // Call the constructor
        
parent::__construct($name$value$aClass$title$aTabindex$onclick$accesskey);
        
$this->multiple $multiple;
        
$this->size     $size;
        
$this->disabled $disabled;
        
$this->options  $options;
        if (
$onchange != '') {
            
$this->onchange $onchange;
            
// TODO : Is it realy this functionality I want ?
            //$this->onchange = 'this.form['.$onchange.'].value=this.options[this.options.selectedIndex].value;';
        
}
    }

    
/**
     * Returns the html for the start of the control 
     * @return String the html
     */
    
function getStart() {
        
$html  '';
        
$html .= '<select';
        
$html .= $this->getAttribute('name');
        
$html .= $this->getAttribute('id');
        
$html .= $this->getAttribute('class');
        
$html .= $this->getAttribute('onchange');
        
$html .= $this->getAttribute('multiple');
        
$html .= $this->getAttribute('size');
        
$html .= $this->getAttribute('disabled');
        
$html .= $this->getAttribute('title');
        
$html .= $this->getAttribute('tabindex');
        
$html .= ">\r\n";
        
$html .= $this->getElements(); // as html
        
if ($this->options !== '' && $this->options instanceof Options ) {
            
$html .= $this->options->getHtml();
        }
        return 
$html;
    }

    
/**
     * Returns the html for the end of the control 
     * including the html for the added elements
     * <code>
     * Usage:
     *    $select = new Select('');
     *    print $select->getEnd(); 
     * </code> 
     * @return String the complete html
     */
    
function getEnd() {
        return 
"</select><br />\r\n";
    }

    
/**
     * Returns the html for the control 
     * including the html for the added elements
     * @return String the complete html
     */
    
function getHtml() {
        
$html  $this->html;
        
$html .= $this->getStart();
        
$html .= $this->getEnd();
        return 
$html;
    }

    
/**
     * Display start html
     * <code>
     * Usage:
     *    Select::start($name, $class, $onchange, $multiple, $size, $disabled, $onclick, $title, $tabindex); 
     * </code> 
     * @static
     * @param String $name      The name of the control
     * @param String $class     The class name
     * @param String $onchange  On Change Event name i.e. 'EMNE'
     * @param String $multiple  The multiple attribute
     * @param String $size      The size attribute
     * @param String $disabled  The disabled
     * @param String $onclick   On Click Event name i.e. 'EMNE'
     * @param String $title     The tooltip
     * @param String $tabindex  The tabindex
     */
    
public static function start($name=''$class=''$onchange=''$multiple=''$size=''$disabled=''$onclick=''$title=''$tabindex='') {
        
$html = new Select($name$class$onchange$multiple$size$disabled$onclick$title$tabindex);
        
$html->addHtml($html->getStart());
    }

    
/**
     * Display end html
     * <code>
     * Usage:
     *    Select::end(); 
     * </code> 
     * @static
     */
    
public static function end() {
        
$html = new Select();
        
$html->addHtml($html->getEnd());
    }

    
/**
     * Display html
     * <code>
     * Usage:
     *    Select::display($name, $class, $onchange, $multiple, $size, $disabled, $options, $title, $tabindex, $accesskey); 
     * </code> 
     * @static
     * @param String $name      The name of the control
     * @param String $class     The class name
     * @param String $onchange  On Change Event name i.e. 'EMNE'
     * @param String $multiple  The multiple attribute
     * @param String $size      The size attribute
     * @param String $disabled  The disabled
     * @param String $options   The new options object
     * @param String $title     The tooltip
     * @param String $tabindex  The tabindex
     */
    
public static function display($name=''$class=''$onchange=''$multiple=''$size=''$disabled=''$options=''$title=''$tabindex='') {
        
$html = new Select($name$class$onchange$multiple$size$disabled$options$title$tabindex);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Select, HTML source code

Den fulde HTML kildekode for Select klassen

<?
<!-- DEBUGSelect -->
<
select name="Test" class="Test" tabindex="1">
<!-- 
DEBUGOption -->
    <
option value="Test">Test</option>

</
select><br />

?>

Vis: Class methods

Select, Class methods

Her er 'klasse metoderne' for Select klassen:

  • __construct
  • getStart
  • getEnd
  • getHtml
  • start
  • end
  • display
  • getValue
  • setId
  • setOnfocus
  • setOnblur
  • id
  • setObject
  • set
  • get
  • getAttribute
  • getTag
  • add
  • getSizeof
  • getElement
  • getElements
  • getToogle
  • getMaximize
  • getMinimize
  • newTriangle
  • getStartHtml
  • getEndHtml
  • showsource
  • getClassName
  • getMsg
  • addHtml
  • __toString
  • getCacheFileName
  • save
  • content

Vis: Object vars

Select, Object vars

Her er 'objekt variable' for Select klassen:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.3.3-7+squeeze9) 1.11
blank.gif