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

Navn : Input.php


Sample code, tutorial

Sådan benyttes komponenten Input klassen

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

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

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

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

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

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

Parent html

Sådan vises komponenten Input klassen



PHP source code

Den fulde PHP kildekode for Input klassen

<?
/**
* @package form
* @see HTML_FORM_COMPONENT_PATH.'/Input.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_BASE_UTIL_PATH.'/Htmlspecialchars.php');
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
* Generates an INPUT element for a form
* <code>
* <input type="$type" name="$name" value="$value" class="$class" size="$size"
*        maxlength="$maxlength" disabled="disabled" readonly="readonly"
*        onclick="$onclick" title="$title" tabindex="$tabindex" accesskey="$accesskey" />
* Usage:
*   $input = new Input($type,$name,$value,$class,$size,$maxlength,
*                      $disabled,$readonly,$onclick,$title,$tabindex,$accesskey);
*   print $input->getHtml();
* Or
*   Input::display($type,$name,$value,$class,$size,$maxlength,
*                  $disabled,$readonly,$onclick,$title,$tabindex,$accesskey);
* </code>
* @package form
*/

class Input extends Element {
    
/**
     *  @var String $type The type of element, i.e. text, radio, checkbox, hidden, ...
     */
    
var $type = '';
    
    
/**
     *  @var String $size The size of the element
     */
    
var $size = '';
    
    
/**
     *  @var String $maxlength The maxlength of chars for a text field
     */
    
var $maxlength = '';
    
    
/**
     *  @var String $disabled The disabled (>IE4.x)
     */
    
var $disabled = '';
    
    
/**
     *  @var String $readonly The readonly (>IE4.x)
     */
    
var $readonly = '';
    
    
/**
     *  @var String $checked Radio/checkbox ticked or not
     */
    
var $checked = '';
    
    
/**
     *  @var boolean $debug Debug may be disabled by the container (false)
     */
    
var $debug = true;

    
/**
     * Constructor
     * @param String $type  The type (text, radio, checkbox, file, button, hidden, submit, reset)
     * @param String $name  The name
     * @param String $value The value, if any
     * @param String $class The class
     * @param String $size  The size / or checked for radio/checkbox
     * @param String $maxlength The maxlength
     * @param String $disabled  The disabled
     * @param String $readonly  The readonly
     * @param String $onclick   On click event for javascript
     * @param String $title     The tooltip
     * @param String $tabindex  The tabindex
     * @param String $accesskey The accesskey
     */
    
function Input($type='',$name='',$value='',$class='',$size='',$maxlength='',$disabled='',$readonly='',$onclick='',$title='',$tabindex='',$accesskey='') {
        
$this->type = strtolower($type!=''?$type:'text');
        
$aTabindex = '';
        if (
$this->type!='hidden' && $disabled=='' && $readonly=='') {
            
$aTabindex  = $tabindex!=''?$tabindex:Tabindex::next();
        }
        
$theAcesskey = '';
        if (
$disabled=='' && $readonly=='') {
            
$theAcesskey = $accesskey;
        }
        
$this->Element($name,$value,$class,$title,$aTabindex,$onclick,$theAcesskey);
        
        switch (
$this->type) {
            case
'text': // Intentionally fall through
            
case 'password':
                if (
$this->title=='') {
                    
$this->title = $this->value;
                }
                
// Intentionally fall through
            
case 'hidden':
                 
// Translate html special chars and remove slashes
// 2007-08-04 changed to htmlspecialchars because of the Gui::display()
// 2008-01-28 Removed again and changed Element to                     
                //$this->value     = Htmlspecialchars::encode($this->value);
                //$this->value     = Htmlspecialchars::encode($value);
//                $this->value     = stripslashes($this->value);
                
$this->maxlength = $maxlength!=''?$maxlength:TEXT_MAXLENGTH;
                
$this->disabled  = $disabled;
                
$this->readonly  = $readonly;
                
$this->size      = $size;
                
$this->class     = $class!=''?$class:CSS_TEXT_CLASS;
                break;
            case
'radio': // Intentionally fall through
            
case 'checkbox':
                
$this->class     = $class!=''?$class:'';
                break;
            case
'file':
                
$this->class = $class!=''?$class:CSS_FILE_BUTTON;
                
// Intentionally fall through
            
case 'reset':
            case
'submit':
            case
'button':
                
$this->disabled = $disabled;
                
$this->class    = $class!=''?$class:CSS_BUTTON;
                if (
$this->title=='') {
                    
$this->title = $this->value;
                    if (
$this->accesskey!='') {
                        
$this->title .= ' (Alt + '.$this->accesskey.')';
                    }
                }
                break;
            case
'image':
                
// Ignore
                
break;
            default:
                
$msg = $this->getClassName().'(), unknown input type='.$this->type;
                if (
defined('HTML_LOG_UTIL_PATH')) {
                    
Log::fatal(__FILE__,__LINE__,$msg);
                    
$html = $this->getMsg(LOG_LEVEL_FATAL, $msg);
                } else {
                    die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".$msg);
                }
                break;
        }
        
        
/**
         * The request parameters will NOT overrule the default parameters
         */
        
switch ($this->type) {
            case
'password':
            case
'hidden': // Intentionally fall through
            
case 'text':
//                if ($this->value=='' && isset($_GET[$this->name])) {
//                    $this->value = Htmlspecialchars::encode($_GET[$this->name]);
//                }
//                if ($this->value=='' && isset($_POST[$this->name])) {
//                    $this->value = Htmlspecialchars::encode($_POST[$this->name]);
//                }
                 
break;
            case
'radio':
                if (isset(
$this->value) && $this->value!=='') {
                    
// Ok, a value is supplied, else force the user to add one
                
} else {
                    
$this->value = defined('LANGUAGE_NONE')?LANGUAGE_NONE:INPUT_VALUE_NONE;
                }
                
// Intentionally fall through
            
case 'checkbox':
                
$this->checked = $size; // 'size' is used as a placeholder for checked for radio/checkbox
                
if (isset($_GET[$this->name])) {
                    
$this->checked = ($_GET[$this->name]==$this->value || $_GET[$this->name]=='on')?'checked':'';
                }
                if (isset(
$_POST[$this->name])) {
                    
$this->checked = ($_POST[$this->name]==$this->value || $_POST[$this->name]=='on')?'checked':'';
                }
                break;
            default:
                
// Ignore
                
break;
        }
    }

    
/**
     * Returns the complete html for an input control
     * @return String the complete html
     */
    
function getHtml() {
        
$html  = $this->html;
        if (
$this->type=='hidden' && $this->name=='') {
            
$html .= '<!-- Input type=hidden name="'.$this->name.'" is empty -->';
        } else {
            
$html .= '<input';
            
$html .= $this->getAttribute('type');
            
$html .= $this->getAttribute('name');
            
$html .= $this->getAttribute('id');
            
// Special handling of the value attribute
            
switch ($this->type) {
                case
'hidden':
                    
$html .= ' value'.'="'.$this->getValue().'"';
                    break;
                case
'text':
                case
'password':
                    
$html .= $this->getAttribute('class');
                    
$html .= $this->getAttribute('size');
                    
$html .= $this->getAttribute('maxlength');
                    
$html .= $this->getAttribute('disabled');
                    
$html .= $this->getAttribute('readonly');
                    
$html .= $this->getAttribute('onclick');
                    
$html .= $this->getAttribute('value');
                    break;
                case
'checkbox':
                case
'radio':
                    
$html .= $this->getAttribute('onclick');
                    
$html .= $this->getAttribute('class');
                    
$html .= $this->getAttribute('checked');
                    
$html .= ' value'.'="'.$this->getValue().'"';
                    break;
                case
'reset':
                case
'submit':
                case
'button':
                    
$html .= $this->getAttribute('disabled');
                    
$html .= $this->getAttribute('class');
                    
$html .= "\r\n\t";
                    
$html .= $this->getAttribute('onclick');
                    
$html .= $this->getAttribute('value');
                    break;
                case
'file':
                    
$html .= $this->getAttribute('class');
                     break;
                case
'image':
                    
$html .= " NOT TESTED ";
                    break;
                default:
                    
$msg = $this->getClassName().'->getHtml(), unknown input type '.$this->type;
                    if (
defined('HTML_LOG_UTIL_PATH')) {
                        
Log::fatal(__FILE__,__LINE__,$msg);
                        
$html .= $this->getMsg(LOG_LEVEL_FATAL, $msg);
                    } else {
                        
$html .= $msg;
                    }
                    break;
            }
            if (
strpos($this->title,"\r\n")!==false) {
                
/**
                 * @todo Does only work in IE, not FireFox
                 */
                
$this->title = str_replace("\r\n","&#013;",$this->title); // <br>
            
}
            
$html .= $this->getAttribute('title');
            
$html .= $this->getAttribute('tabindex');
            
$html .= $this->getAttribute('accesskey');
            if (
$this->type=='file') {
                
$html .= $this->getAttribute('accept');
            }
            
$html .= ' />';
            if (
$this->type=='password') {
                
$html .= '<br />';
            }
            if (
$this->type=='text') {
                
$html .= '<br />'; // Ignore zip,  && $this->name!=SELECT_ZIP
            
}
        }
        
$html .= $this->getElements(); // as html
        
if ($html!='') {
            
$html .= "\r\n";
            if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_HIDDEN && ($this->type=='hidden' || $this->type=='readonly')) {
                
// Debug may be disabled by the container
                
if ($this->debug===true) {
                    
$html .= "<!-- DEBUG Hidden: ".ucfirst($this->type).": name=$this->name value=$this->value -->\r\n";
                }
            }
        }
        return
$html;
    }

    
/**
     * Display the html for the input element
     * <code>
     * Usage:
     *    Input::display($type,$name,$value,$class,$size,$maxlength,$disabled,
     *                   $readonly,$onclick,$title,$tabindex,$accesskey);
     * </code>
     * @static
     * @param String $type  The type (text, radio, checkbox, file, button, hidden, submit, reset)
     * @param String $name  The name
     * @param String $value The value, if any
     * @param String $class The class
     * @param String $size  The size / or checked for radio/checkbox
     * @param String $maxlength The maxlength
     * @param String $disabled  The disabled
     * @param String $readonly  The readonly
     * @param String $onclick   On click event for javascript
     * @param String $title     The tooltip
     * @param String $tabindex  The tabindex
     * @param String $accesskey The accesskey
     */
    
function display($type='',$name='',$value='',$class='',$size='',$maxlength='',$disabled='',$readonly='',$onclick='',$title='',$tabindex='',$accesskey='') {
        
$html = new Input($type,$name,$value,$class,$size,$maxlength,$disabled,$readonly,$onclick,$title,$tabindex,$accesskey);
        
$html->addHtml();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Input klassen

<?
<input type="text" class="formXLARGE baseBorder baseBody" tabindex="1" /><br />

?>

Class methods

Her er 'klasse metoderne' for Input klassen:

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

Object vars

Her er 'objekt variable' for Input klassen:

  • html =>
  • sql =>
  • elements => Array
  • sizeof => 0
  • name =>
  • id =>
  • value =>
  • class => formXLARGE baseBorder baseBody
  • title =>
  • tabindex => 1
  • onclick =>
  • accesskey =>
  • onfocus =>
  • onblur =>
  • type => text
  • size =>
  • maxlength =>
  • disabled =>
  • readonly =>
  • checked =>
  • debug => 1

Input

Vis denne side på danmark

Vis denne side på Germany

Vis denne side på England

Vis denne side på France

Vis denne side på Italy

Vis denne side på Norge

Vis denne side på Sverige

Vis denne side på USA


 
Input