[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/class/xoopsform/ -> formelement.php (source)

   1  <?php
   2  // $Id: formelement.php 984 2007-08-11 16:31:54Z phppp $

   3  //  ------------------------------------------------------------------------ //

   4  //                XOOPS - PHP Content Management System                      //

   5  //                    Copyright (c) 2000 XOOPS.org                           //

   6  //                       <http://www.xoops.org/>                             //

   7  //  ------------------------------------------------------------------------ //

   8  //  This program is free software; you can redistribute it and/or modify     //

   9  //  it under the terms of the GNU General Public License as published by     //

  10  //  the Free Software Foundation; either version 2 of the License, or        //

  11  //  (at your option) any later version.                                      //

  12  //                                                                           //

  13  //  You may not change or alter any portion of this comment or credits       //

  14  //  of supporting developers from this source code or any supporting         //

  15  //  source code which is considered copyrighted (c) material of the          //

  16  //  original comment or credit authors.                                      //

  17  //                                                                           //

  18  //  This program is distributed in the hope that it will be useful,          //

  19  //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //

  20  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //

  21  //  GNU General Public License for more details.                             //

  22  //                                                                           //

  23  //  You should have received a copy of the GNU General Public License        //

  24  //  along with this program; if not, write to the Free Software              //

  25  //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //

  26  //  ------------------------------------------------------------------------ //

  27  // Author: Kazumi Ono (AKA onokazu)                                          //

  28  // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //

  29  // Project: The XOOPS Project                                                //

  30  // ------------------------------------------------------------------------- //

  31  if (!defined('XOOPS_ROOT_PATH')) {
  32      die("XOOPS root path not defined");
  33  }
  34  /**

  35   * 

  36   * 

  37   * @package     kernel

  38   * @subpackage  form

  39   * 

  40   * @author        Kazumi Ono    <onokazu@xoops.org>

  41   * @copyright    copyright (c) 2000-2003 XOOPS.org

  42   */
  43  
  44  
  45  /**

  46   * Abstract base class for form elements

  47   * 

  48   * @author    Kazumi Ono    <onokazu@xoops.org>

  49   * @copyright    copyright (c) 2000-2003 XOOPS.org

  50   * 

  51   * @package     kernel

  52   * @subpackage  form

  53   */
  54  class XoopsFormElement {
  55  
  56      /**

  57       * Javascript performing additional validation of this element data

  58       *

  59       * This property contains a list of Javascript snippets that will be sent to

  60       * XoopsForm::renderValidationJS().

  61       * NB: All elements are added to the output one after the other, so don't forget

  62       * to add a ";" after each to ensure no Javascript syntax error is generated.

  63       * 

  64       * @var array()  

  65       */
  66      var $customValidationCode = array();
  67  
  68      /**#@+

  69       * @access private

  70       */
  71      /**

  72       * "name" attribute of the element

  73       * @var string  

  74       */
  75      var $_name;
  76  
  77      /**

  78       * caption of the element

  79       * @var    string

  80       */
  81      var $_caption;
  82  
  83      /**

  84       * Accesskey for this element

  85       * @var    string

  86       */
  87      var $_accesskey = '';
  88  
  89      /**

  90       * HTML class for this element

  91       * @var    string

  92       */
  93      var $_class = '';
  94  
  95      /**

  96       * hidden?

  97       * @var    bool

  98       */
  99      var $_hidden = false;
 100  
 101      /**

 102       * extra attributes to go in the tag

 103       * @var    string

 104       */
 105      var $_extra = "";
 106  
 107      /**

 108       * required field?

 109       * @var    bool

 110       */
 111      var $_required = false;
 112  
 113      /**

 114       * description of the field

 115       * @var    string

 116       */
 117      var $_description = "";
 118      /**#@-*/

 119  
 120  
 121      /**

 122       * constructor

 123       *

 124       */
 125  	function XoopsFormElement(){
 126          exit("This class cannot be instantiated!");
 127      }
 128  
 129      /**

 130       * Is this element a container of other elements?

 131       *

 132       * @return    bool false

 133       */
 134  	function isContainer()
 135      {
 136          return false;
 137      }
 138  
 139      /**

 140       * set the "name" attribute for the element

 141       *

 142       * @param    string  $name   "name" attribute for the element

 143       */
 144  	function setName($name) {
 145          $this->_name = trim($name);
 146      }
 147  
 148      /**

 149       * get the "name" attribute for the element

 150       *

 151       * @param    bool    encode?

 152       * @return    string  "name" attribute

 153       */
 154  	function getName($encode=true) {
 155          if (false != $encode) {
 156              return str_replace("&amp;", "&", str_replace("'","&#039;",htmlspecialchars($this->_name)));
 157          }
 158          return $this->_name;
 159      }
 160  
 161      /**

 162       * set the "accesskey" attribute for the element

 163       *

 164       * @param    string  $key   "accesskey" attribute for the element

 165       */
 166  	function setAccessKey($key) {
 167          $this->_accesskey = trim($key);
 168      }
 169      /**

 170       * get the "accesskey" attribute for the element

 171       *

 172       * @return     string  "accesskey" attribute value

 173       */
 174  	function getAccessKey() {
 175          return $this->_accesskey;
 176      }
 177      /**

 178       * If the accesskey is found in the specified string, underlines it

 179       *

 180       * @param    string  $str   String where to search the accesskey occurence

 181       * @return     string  Enhanced string with the 1st occurence of accesskey underlined

 182       */
 183  	function getAccessString( $str ) {
 184          $access = $this->getAccessKey();
 185          if ( !empty($access) && ( false !== ($pos = strpos($str, $access)) ) ) {
 186              return substr($str, 0, $pos) . '<span style="text-decoration:underline">' . substr($str, $pos, 1) . '</span>' . substr($str, $pos+1);
 187          }
 188          return $str;
 189      }
 190  
 191      /**

 192       * set the "class" attribute for the element

 193       *

 194       * @param    string  $key   "class" attribute for the element

 195       */
 196  	function setClass($class) {
 197          $class = trim($class);
 198          if ( empty($class) ) {
 199              $this->_class = '';
 200          } else {
 201              $this->_class .= (empty($this->_class) ? '' : ' ') . $class;
 202          }
 203      }
 204      /**

 205       * get the "class" attribute for the element

 206       *

 207       * @return     string  "class" attribute value

 208       */
 209  	function getClass() {
 210          return $this->_class;
 211      }
 212  
 213      /**

 214       * set the caption for the element

 215       *

 216       * @param    string  $caption

 217       */
 218  	function setCaption($caption) {
 219          $this->_caption = trim($caption);
 220      }
 221  
 222      /**

 223       * get the caption for the element

 224       *

 225       * @return    string

 226       */
 227  	function getCaption() {
 228          return $this->_caption;
 229      }
 230  
 231      /**

 232       * set the element's description

 233       *

 234       * @param    string  $description

 235       */
 236  	function setDescription($description) {
 237          $this->_description = trim($description);
 238      }
 239  
 240      /**

 241       * get the element's description

 242       *

 243       * @return    string

 244       */
 245  	function getDescription() {
 246          return $this->_description;
 247      }
 248  
 249      /**

 250       * flag the element as "hidden"

 251       *

 252       */
 253  	function setHidden() {
 254          $this->_hidden = true;
 255      }
 256  
 257      /**

 258       * Find out if an element is "hidden".

 259       *

 260       * @return    bool

 261       */
 262  	function isHidden() {
 263          return $this->_hidden;
 264      }
 265  
 266      /**

 267       * Find out if an element is required.

 268       *

 269       * @return    bool

 270       */
 271  	function isRequired() {
 272          return $this->_required;
 273      }
 274  
 275      /**

 276       * Add extra attributes to the element.

 277       *

 278       * This string will be inserted verbatim and unvalidated in the

 279       * element's tag. Know what you are doing!

 280       *

 281       * @param    string  $extra

 282       * @param   string  $replace If true, passed string will replace current content otherwise it will be appended to it

 283       * @return    string New content of the extra string

 284       */
 285  	function setExtra($extra, $replace = false){
 286          if ( $replace) {
 287              $this->_extra = " " . trim($extra);
 288          } else {
 289              $this->_extra .= " " . trim($extra);
 290          }
 291          return $this->_extra;
 292      }
 293  
 294      /**

 295       * Get the extra attributes for the element

 296       *

 297       * @return    string

 298       */
 299  	function getExtra(){
 300          if (isset($this->_extra)) {
 301              return $this->_extra;
 302          }
 303      }
 304  
 305      /**

 306       * Render custom javascript validation code

 307       *

 308       * @seealso XoopsForm::renderValidationJS

 309      */
 310  	function renderValidationJS() {
 311          // render custom validation code if any

 312          if ( !empty( $this->customValidationCode ) ) {
 313              return implode( "\n", $this->customValidationCode );
 314          // generate validation code if required 

 315          } elseif ($this->isRequired()) {
 316              $eltname    = $this->getName();
 317              $eltcaption = trim( $this->getCaption() );
 318              $eltmsg = empty($eltcaption) ? sprintf( _FORM_ENTER, $eltname ) : sprintf( _FORM_ENTER, $eltcaption );
 319              $eltmsg = str_replace('"', '\"', stripslashes( $eltmsg ) );
 320              return "if ( myform.{$eltname}.value == \"\" ) { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }";
 321          }
 322          return ''; 
 323      }
 324  
 325      /**

 326       * Generates output for the element.

 327       *

 328       * This method is abstract and must be overwritten by the child classes.

 329       * @abstract

 330       */
 331  	function render(){
 332      }
 333  }
 334  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics