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

Source for file EMailTextInput.class.php

Documentation is available at EMailTextInput.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>\r\n";
  14.    echo "Example: define( 'CLASSPATH', '../path/to/classes/' );\r\n";
  15.    exit();
  16. }
  17.  
  18. if defined"LANG" ) )
  19.    /**
  20.     * Including language specific messages.
  21.     */
  22.    include CLASSPATH."/forms/items/EMailTextInput/".LANG.".inc.php";
  23. else
  24. {
  25.    echo "<h3>You have to define the constant LANG!</h3>\n";
  26.    echo "Example for german: define( 'LANG', 'de' );\n";
  27.    exit();
  28. }
  29.  
  30.  
  31.  
  32. /**
  33.  *
  34.  */
  35. require_once CLASSPATH."forms/items/HTMLTextInput.class.php";
  36. /**
  37.  *
  38.  */
  39. include_once CLASSPATH."RegExpConstants.inc.php";
  40.  
  41. /**
  42.  * A class to generate text input fields for email-input.
  43.  *
  44.  * @package    forms
  45.  * @subpackage items
  46.  * @version    0.1.51
  47.  * @since      0.7.0.0
  48.  * @author     Daniel Plücken <daniel@debakel.net>
  49.  * @license    http://www.gnu.org/copyleft/lesser.html
  50.  *              GNU Lesser General Public License
  51.  * @copyright  Copyright (C) 2003 Daniel Plücken <daniel@debakel.net>
  52.  *
  53.  *  This library is free software; you can redistribute it and/or
  54.  *  modify it under the terms of the GNU Lesser General Public
  55.  *  License as published by the Free Software Foundation; either
  56.  *  version 2.1 of the License.
  57.  *
  58.  *  This library is distributed in the hope that it will be useful,
  59.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  60.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  61.  *  GNU Lesser General Public License for more details.
  62.  *
  63.  *  You should have received a copy of the GNU Lesser General
  64.  *  Public License along with this library; if not, write to the
  65.  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  66.  *  Boston, MA 02111-1307 USA
  67.  */
  68. class EMailTextInput extends HTMLTextInput
  69. {
  70.    /**
  71.     * Constructor
  72.     *
  73.     * @version 1.0
  74.     * @since   0.1.0
  75.     * @author  Daniel Plücken <daniel@debakel.net>
  76.     * @access  public
  77.     * @param   string  $name* 
  78.     * @param   string  $value* 
  79.     * @param   integer $size* 
  80.     * @param   integer $maxchar* 
  81.     */
  82.    function EMailTextInput(
  83.                                  $name     "",
  84.                                  $value    "",
  85.                                  $size     0,
  86.                                  $maxchars 0
  87.                               )
  88.    {
  89.        parent::HTMLTextInput(
  90.                                 $name,
  91.                                 $value,
  92.                                 $size,
  93.                                 $maxchars
  94.                             );
  95.  
  96.        parent::setOnBlur"checkEmail( this );" );
  97.    }
  98.  
  99.  
  100.  
  101.    /**
  102.     * Stores the value of this item's "onBlur"-attribute.
  103.     *
  104.     * @version 1.0
  105.     * @since   0.1.1
  106.     * @author  Daniel Plücken <daniel@debakel.net>
  107.     * @access  public
  108.     * @param   string $string 
  109.     * @return  void 
  110.     */
  111.    function setOnBlur$string )
  112.    parent::setOnBlur"checkEmail( this );".$string )}
  113.  
  114.  
  115.  
  116.    /**
  117.     * Returns a javascript to probe if the value, that was typed in the
  118.     * textfield, is an email.
  119.     *
  120.     * @version 1.51
  121.     * @since   0.1.0
  122.     * @author  Daniel Plücken <daniel@debakel.net>
  123.     * @access  public
  124.     * @return  void 
  125.     */
  126.    function getJSFunctionsToCheckEmail()
  127.    {
  128.       global $JSTOCHECKEMAIL;
  129.  
  130.       if empty$JSTOCHECKEMAIL ) )
  131.       {
  132.          $JSTOCHECKEMAIL true;
  133.  
  134.          $out  "\r\n\r\n<script language=\"javascript\">\r\n";
  135.          $out .= "<!--\r\n\r\n";
  136.          $out .= "  window.checkEmail = function( which )\r\n";
  137.          $out .= "  {\r\n";
  138.          $out .= "     string = which.value;\r\n\r\n";
  139.          $out .= "     if( string == \"\" )\r\n";
  140.          $out .= "       return true;\r\n";
  141.          $out .= "     else\r\n";
  142.          $out .= "     {\r\n";
  143.          $out .= "        pattern = /^[-a-zA-Z0-9_.]+@"
  144.                                        ."(([-a-zA-Z0-9]+\\.)+"  // domain
  145.                                        ."[a-z]{2,4}"
  146.                                      ."|\[?([0-9]{1,3}\.){3,3}" // ip
  147.                                        ."[0-9]{1,3}\]?)$/;\r\n";
  148.          $out .= "        if( pattern.test( string ) )\r\n";
  149.          $out .= "           return true;\r\n";
  150.          $out .= "        else\r\n";
  151.          $out .= "        {\r\n";
  152.          $out .= "           alert( unescape( \"".JS_ERR_MSG."\" ) );\r\n";
  153.          $out .= "           which.focus();\r\n";
  154.          $out .= "           return false;\r\n";
  155.          $out .= "        }\r\n";
  156.          $out .= "     }\r\n";
  157.          $out .= "  }\r\n";
  158.          $out .= "// -->\r\n";
  159.          $out .= "</script>\r\n\r\n\r\n";
  160.       }
  161.  
  162.       return $out;
  163.    }
  164.  
  165.  
  166.  
  167.    /**
  168.     * Returns an if-order of a javascript to check whether the value of this
  169.     * item has the correct format.
  170.     *
  171.     * @version 1.1
  172.     * @since   0.1.2
  173.     * @author  Daniel Plücken <daniel@debakel.net>
  174.     * @access  public
  175.     * @return  string 
  176.     */
  177.    function getValidationOrder()
  178.    {
  179.       $out "checkEmail( document."
  180.                          .$this->parentform->name."."
  181.                          .$this->name
  182.                      ." )";
  183.  
  184.       return $out;
  185.    }
  186.  
  187.  
  188.  
  189.    /**
  190.     * Generates the sourcecode to build this object and returns it.
  191.     *
  192.     * @version 1.0
  193.     * @since   0.1.0
  194.     * @author  Daniel Plücken <daniel@debakel.net>
  195.     * @access  public
  196.     * @return  string 
  197.     */
  198.    function getPHPSource()
  199.    {
  200.       $out  "unset( \x24value );\r\n";
  201.       $out .= "\x24value = \x24_POST[\"".$this->getName()."\"]\r\n"
  202.                    ."        .\x24_GET[\"".$this->getName()."\"];\r\n";
  203.       $out .= "\x24input[] = new EMailTextInput(\r\n"
  204.          ."                                \"".$this->getName()."\",\r\n"
  205.          ."                                \x24value,\r\n"
  206.          ."                                \"".$this->getSize()."\",\r\n"
  207.          ."                                \"".$this->getMaxChars()."\"\r\n"
  208.          ."                             );\r\n";
  209.  
  210.       $tmp $this->getValue();
  211.       $out .= !empty$tmp )
  212.                     ? "if( \x24value === \"\" )\r\n"
  213.                      ."  \x24input[count(\x24input)-1]"
  214.                         ."->setValue( \"".$tmp."\" );\r\n\r\n"
  215.                     : "\r\n";
  216.  
  217.       return $out;
  218.    }
  219.  
  220.  
  221.  
  222.    /**
  223.     * Returns a generated string based on the attributes of this object.
  224.     *
  225.     * @version 1.1
  226.     * @since   0.1.0
  227.     * @author  Daniel Plücken <daniel@debakel.net>
  228.     * @access  public
  229.     * @return  string 
  230.     */
  231.    function get$type "" )
  232.    {
  233.       ifempty$type ) )
  234.         $type "text";
  235.  
  236.       $out  $this->getJSFunctionsToCheckEmail();
  237.       $out .= parent::get$type );
  238.  
  239.       return $out;
  240.    }
  241. // ENDE class EMailTextInput
  242. ?>

Documentation generated on Thu, 05 Jun 2008 19:11:20 +0200 by phpDocumentor 1.4.1