forms
[ class tree: forms ] [ index: forms ] [ all elements ]

Source for file HTMLTextInput.class.php

Documentation is available at HTMLTextInput.class.php

  1. <?php
  2. /**
  3.  * For including this file you have to define the constant "CLASSPATH".
  4.  * Because every include in the framework depends on the CLASSPATH definition.
  5.  * The CLASSPATH means the relative path to the folder that contains the
  6.  * framework GilliGan.
  7.  *
  8.  * @package    forms
  9.  * @subpackage items
  10.  */
  11. if!defined"CLASSPATH" ) )
  12. {
  13.   echo "<h3>You have to define the constant CLASSPATH!</h3>\n";
  14.   echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\n";
  15.   exit();
  16. }
  17.  
  18. /**
  19.  *
  20.  */
  21. require_onceCLASSPATH."forms/items/ABSTHTMLTextInput.class.php" );
  22.  
  23. /**
  24.  * A class to generate text input fields.
  25.  *
  26.  * @package    forms
  27.  * @subpackage items
  28.  * @version    0.1.25
  29.  * @static
  30.  * @author     Daniel Plücken <daniel@debakel.net>
  31.  * @license    http://www.gnu.org/copyleft/lesser.html
  32.  *              GNU Lesser General Public License
  33.  * @copyright  Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
  34.  *
  35.  *  This library is free software; you can redistribute it and/or
  36.  *  modify it under the terms of the GNU Lesser General Public
  37.  *  License as published by the Free Software Foundation; either
  38.  *  version 2.1 of the License.
  39.  *
  40.  *  This library is distributed in the hope that it will be useful,
  41.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  42.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  43.  *  GNU Lesser General Public License for more details.
  44.  *
  45.  *  You should have received a copy of the GNU Lesser General
  46.  *  Public License along with this library; if not, write to the
  47.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  48.  *  Boston, MA 02111-1307 USA
  49.  */
  50. {
  51.    /**
  52.     * Carries the text that should be shown if the textfields value is empty.
  53.     *
  54.     * @var    string 
  55.     * @access public
  56.     */
  57.    var $standard_text = "";
  58.  
  59.    /**
  60.     * Constructor
  61.     *
  62.     * @version 1.0
  63.     * @since   0.1.0
  64.     * @author  Daniel Plücken <daniel@debakel.net>
  65.     * @access  public
  66.     * @param   string  $name 
  67.     * @param   string  $value 
  68.     * @param   integer $size 
  69.     * @param   integer $maxchar 
  70.     * @param   string  $style_class 
  71.     * @param   string  $other_attributes 
  72.     */
  73.    function HTMLTextInput(
  74.                            $name             "",
  75.                            $value            "",
  76.                            $size             0,
  77.                            $maxchars         0,
  78.                            $style_class      "",
  79.                            $other_attributes ""
  80.                          )
  81.    {
  82.       parent::__constructor(
  83.                                $name,
  84.                                $value,
  85.                                $size,
  86.                                $maxchars,
  87.                                $style_class,
  88.                                $other_attributes
  89.                            );
  90.    }
  91.  
  92.  
  93.  
  94.    /**
  95.     * Makes a clone of this object an returns a reference to this clone.
  96.     *
  97.     * @version 1.1
  98.     * @since   0.1.0
  99.     * @author  Daniel Plücken <daniel@debakel.net>
  100.     * @access  public
  101.     * @param   string  $newName 
  102.     * @param   integer $maxchars Zero means no limit.
  103.     * @param   integer $size     Zero means no preference.
  104.     * @return  HTMLTextInput 
  105.     */
  106.    function getClone(
  107.                       $newName,
  108.                       $maxchars      0,
  109.                       $size          0,
  110.                       $selectedValue ""
  111.                     )
  112.    {
  113.       $maxchars      preg_match"^\d*$"$maxchars )
  114.                        ? $maxchars
  115.                        : $this->maxchars;
  116.       $size          preg_match"^\d*$"$size )
  117.                        ? $size
  118.                        : $this->size;
  119.       $selectedValue !empty$selectedValue )
  120.                        ? $selectedValue
  121.                        : $this->value;
  122.  
  123.       $newInstance new HTMLTextInput(
  124.                                         $newName,
  125.                                         $selectedValue,
  126.                                         $size,
  127.                                         $maxchars
  128.                                       );
  129.  
  130.       if!empty$this->onBlur ) )
  131.         $newInstance->setOnBlur$this->onBlur );
  132.  
  133.       if!empty$this->style_class ) )
  134.         $newInstance->setStyle$this->style_class );
  135.  
  136.       if!empty$this->other_attributes ) )
  137.         $newInstance->setAttributes$this->other_attributes );
  138.  
  139.       return $newInstance;
  140.    }
  141.  
  142.  
  143.  
  144.    /**
  145.     * Sets the text that should be shown if the textfields value is empty.
  146.     *
  147.     * @version 1.1
  148.     * @since   0.1.25
  149.     * @author  Daniel Plücken <daniel@debakel.net>
  150.     * @param   string $string 
  151.     * @access  public
  152.     * @return  void 
  153.     */
  154.    function setStandardText$string )
  155.    $this->standard_text = $string}
  156.  
  157.  
  158.  
  159.    /**
  160.     * Generates the sourcecode to build this object and returns it.
  161.     *
  162.     * @version 1.1
  163.     * @since   0.1.0
  164.     * @author  Daniel Plücken <daniel@debakel.net>
  165.     * @param   string $type 
  166.     * @access  public
  167.     * @return  string 
  168.     */
  169.    function getPHPSource$type "" )
  170.    {
  171.      ifempty$type ) )
  172.        $type "HTMLTextInput";
  173.  
  174.      return parent::getPHPSource$type );
  175.    }
  176.  
  177.  
  178.  
  179.    /**
  180.     * Returns a generated string based on the attributes of this object.
  181.     *
  182.     * @version 1.23
  183.     * @since   0.1.0
  184.     * @author  Daniel Plücken <daniel@debakel.net>
  185.     * @param   string $type 
  186.     * @access  public
  187.     * @return  string 
  188.     */
  189.    function get$type "" )
  190.    {
  191.         if !empty$this->standard_text ) )
  192.         {
  193.             if !preg_match"!;$!"$this->focus ) )
  194.                $this->focus .= ";";
  195.  
  196.             $this->focus .= "if(this.value=='"
  197.                            .addslashes$this->standard_text )
  198.                            ."')this.value=''";
  199.  
  200.             if !preg_match"!;$!"$this->blur ) )
  201.                $this->blur .= ";";
  202.  
  203.             $this->blur .= "if(this.value=='')this.value='"
  204.                           .addslashes$this->standard_text )
  205.                           ."'";
  206.  
  207.             if empty$this->value ) )
  208.                $this->value = $this->standard_text;
  209.         }
  210.  
  211.  
  212.         if empty$type ) )
  213.            $type "text";
  214.  
  215.         return parent::get$type );
  216.    }
  217. // END of class HTMLTextInput
  218. ?>

Documentation generated on Thu, 05 Jun 2008 19:13:27 +0200 by phpDocumentor 1.4.1