blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Form  /  Select   Login nu   Login
blank.gif
 ««« Se kilde koden
blank.gif
triangle.gif Basic Base Component Db Dto Form  Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util
blank.gif
blank.gif
 
arrow-headline.gif Index
 
  Tilbage

Navn : Select.php


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();
    ?>

Parent html

Sådan vises komponenten Select klassen



PHP source code

Den fulde PHP kildekode for Select klassen

<?
/**
* @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.10
* @since 22-feb-2007
*/

/**
* 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
*   $options = 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'=>''),
*   );
*   $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('$options,$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($options,$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
     */
    
var $onchange = '';

    
/**
     * @var String $multiple The multiple select attribute
     */
    
var $multiple = '';

    
/**
     * @var String $size The size
     */
    
var $size = '';

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

    
/**
     * @var Options $options The new options object
     */
    
var $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 Select($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
        
$this->Element($name,$value,$aClass,$title,$aTabindex,$onclick,$accesskey);
        
$this->multiple = $multiple;
        
$this->size     = $size;
        
$this->disabled = $disabled;
        
$this->options  = $options;
        if (
$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 != '' && is_a($this->options, CLASS_NAME_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
     */
    
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
     */
    
function end() {
        
$html = new Html();
        
$html->addHtml(Select::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
     */
    
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();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Select klassen

<?
<select name="Test" class="Test" tabindex="1">
    <
option value="Test">Test</option>

</
select><br />

?>

Class methods

Her er 'klasse metoderne' for Select klassen:

  • object
  • getclassname
  • getmsg
  • addhtml
  • gethtml
  • tostring
  • getcachefilename
  • save
  • content
  • html
  • setobject
  • set
  • get
  • getattribute
  • gettag
  • add
  • getsizeof
  • getelement
  • getelements
  • gettoogle
  • getmaximize
  • getminimize
  • newtriangle
  • display
  • showsource
  • element
  • getvalue
  • setid
  • setonfocus
  • setonblur
  • id
  • select
  • getstart
  • getend
  • start
  • end

Object vars

Her er 'objekt variable' for Select klassen:

  • html =>
  • sql =>
  • elements => Array
  • sizeof => 1
  • name => Test
  • id =>
  • value =>
  • class => Test
  • title =>
  • tabindex => 1
  • onclick =>
  • accesskey =>
  • onfocus =>
  • onblur =>
  • onchange =>
  • multiple =>
  • size =>
  • disabled =>
  • options =>

 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif