Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Validator  /  Validator   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tl.gif Cms tr.gif tl.gif Component tr.gif tl.gif Db tr.gif tl.gif Db-basket tr.gif tl.gif Db-login tr.gif tl.gif Db-customer tr.gif tl.gif Db-select tr.gif tl.gif Jquery tr.gif tl.gif Form-elements tr.gif tl.gif Menu-fisheye tr.gif tl.gif Template tr.gif tl.gif Tree-node tr.gif tls.gif     Validator  trs.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Validator.php


Vis: Sample code, tutorial

Validator, Sample code, tutorial

Sådan benyttes komponenten Validator klassen

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

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

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

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

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

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

Skjul: Sådan vises komponenten

Validator, Sådan vises komponenten

Sådan vises komponenten Validator klassen


Vis: PHP source code

Validator, PHP source code

Den fulde PHP kildekode for Validator klassen

<?php
/**
 * @package validator
 * @filesource
 * @see HTML_VALIDATOR_COMPONENT_PATH.'/Validator.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_COMMON_PATH.'/Html.php');
require_once(
HTML_BASE_UTIL_PATH.'/Ul.php');
require_once(
HTML_BASE_UTIL_PATH.'/Li.php');
require_once(
HTML_BASIC_UTIL_PATH.'/Singleton.php');
require_once(
HTML_VALIDATOR_COMPONENT_PATH.'/ValidatorErrorList.php');
if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
    require_once(
HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
}

/**
 * Validates the different controls for a form. Ready to use
 * 
 * 
 * @todo how do I use this validator ????????????????????????
 * - should check the boundaries, pattern, 
 * - should generate localized error messages
 * 
 * <code>
 * Usage:
 *   $validator = new Validator();
 *   print $validator->getHtml();
 * Or
 *   print $validator->getStart();
 *   print $validator->getEnd();
 * Or
 *   Validator::start();
 *   Validator::end();
 * Or
 *   Validator::display();
 * </code>
 * @package validator
 */

class Validator extends Html {
    
/**
     * Constructor
     */
    
function __construct() {
        
parent::__construct();
       }
       
    
/**
     * Returns the html for the start of the control 
     * @return String the html
     */
    
function getStart() {
        
$html  '';
        
$ul = new Ul(CSS_ERROR);
           
$errorlist = & Singleton::getInstance(CLASS_VALIDATOR_ERROR_LIST);
        
$html .= $errorlist->size() != $ul->getStart() : "";
        
$html .= $this->getErrorList();
        return 
$html;
    }

    
/**
     * Returns the html for the end of the control 
     * @return String the complete html
     */
    
function getEnd() {
        
$ul = new Ul(CSS_ERROR);
        
$errorlist = & Singleton::getInstance(CLASS_VALIDATOR_ERROR_LIST);
        return 
$errorlist->size() != $ul->getEnd() : "";
    }

    
/**
     * Returns the list of the accumulated error messages as html
     * surronded by LI tags
     * @static 
     * @return array The list of error messages
     */
    
function getErrorList() {
        
$html '';
        
$li   = new Li();
           
$errorlist = & Singleton::getInstance(CLASS_VALIDATOR_ERROR_LIST);
        foreach(
$errorlist->getErrorList() as $key=>$error) {
            
$translatedText $key;
            if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
                
$translatedText Translate::sql($key);
            }
            
$html .= $li->getStart()."<b>$translatedText</b><br />";
            if (
is_array($error)) {
                foreach(
$error as $key=>$value) {
                    switch(
$key) {
                        case 
HTML_ATTRIBUTE_MSG:
                            
$html .= $value";
                            break;
                        default:
                            
//$html .= "<!-- $key=$value -->";
                            
break;
                    }
                }
            } else {
                
$html .= "$error"// No message
            
}
            
$html .= $li->getEnd();
        }
        return 
$html;
    }
    
    
/**
     * Returns the html for the control
     * @return String the complete html
     */
    
function getHtml() {
        
$html  $this->html;
        
        
// TODO FORMAT THE message
        // TODO control.highlight() and control.focus()
        
        
$html .= $this->getStart();
        
$html .= $this->getEnd();
        return 
$html;
    }
    
    
/**
     * Display start html
     * <code>
     * Usage:
     *    Validator::start(); 
     * </code> 
     * @static
     */
    
public static function start() {
        
$html = new Validator();
        
$html->addHtml($html->getStart());
    }

    
/**
     * Display the error list as html
     * <code>
     * Usage:
     *    Validator::errorlist(); 
     * </code> 
     * @static
     */
    
public static function errorlist() {
        
$html = new Validator();
        
$html->addHtml($html->getErrorList());
    }

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

    
/**
    * Display html
    * <code>
    * Usage:
    *    Validator::display(); 
    * </code> 
    * @static
    */
       
public static function display() {
          
$html = new Validator();
          
$html->addHtml();
       }
}
?>

Vis: HTML source code

Validator, HTML source code

Den fulde HTML kildekode for Validator klassen

<?
<!-- DEBUGValidator -->

?>

Vis: Class methods

Validator, Class methods

Her er 'klasse metoderne' for Validator klassen:

  • __construct
  • getStart
  • getEnd
  • getErrorList
  • getHtml
  • start
  • errorlist
  • end
  • display
  • 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

Validator, Object vars

Her er 'objekt variable' for Validator 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+squeeze3) 1.11
blank.gif