formelement.php

Go to the documentation of this file.
00001 <?php
00002 // $Id: formelement.php 1158 2007-12-08 06:24:20Z phppp $
00003 //  ------------------------------------------------------------------------ //
00004 //                XOOPS - PHP Content Management System                      //
00005 //                    Copyright (c) 2000 XOOPS.org                           //
00006 //                       <http://www.xoops.org/>                             //
00007 //  ------------------------------------------------------------------------ //
00008 //  This program is free software; you can redistribute it and/or modify     //
00009 //  it under the terms of the GNU General Public License as published by     //
00010 //  the Free Software Foundation; either version 2 of the License, or        //
00011 //  (at your option) any later version.                                      //
00012 //                                                                           //
00013 //  You may not change or alter any portion of this comment or credits       //
00014 //  of supporting developers from this source code or any supporting         //
00015 //  source code which is considered copyrighted (c) material of the          //
00016 //  original comment or credit authors.                                      //
00017 //                                                                           //
00018 //  This program is distributed in the hope that it will be useful,          //
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
00021 //  GNU General Public License for more details.                             //
00022 //                                                                           //
00023 //  You should have received a copy of the GNU General Public License        //
00024 //  along with this program; if not, write to the Free Software              //
00025 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
00026 //  ------------------------------------------------------------------------ //
00027 // Author: Kazumi Ono (AKA onokazu)                                          //
00028 // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
00029 // Project: The XOOPS Project                                                //
00030 // ------------------------------------------------------------------------- //
00031 if (!defined('XOOPS_ROOT_PATH')) {
00032      die("XOOPS root path not defined");
00033 }
00056 class XoopsFormElement {
00057 
00068      var $customValidationCode = array();
00069 
00077      var $_name;
00078 
00083      var $_caption;
00084 
00089      var $_accesskey = '';
00090 
00095      var $_class = array();
00096 
00101      var $_hidden = false;
00102 
00107      var $_extra = array();
00108 
00113      var $_required = false;
00114 
00119      var $_description = "";
00127      function XoopsFormElement(){
00128           exit("This class cannot be instantiated!");
00129      }
00130 
00136      function isContainer()
00137      {
00138           return false;
00139      }
00140 
00146      function setName($name) {
00147           $this->_name = trim($name);
00148      }
00149 
00156      function getName($encode = true) {
00157           if (false != $encode) {
00158                return str_replace("&amp;", "&", htmlspecialchars($this->_name, ENT_QUOTES));
00159           }
00160           return $this->_name;
00161      }
00162 
00168      function setAccessKey($key) {
00169           $this->_accesskey = trim($key);
00170      }
00176      function getAccessKey() {
00177           return $this->_accesskey;
00178      }
00185      function getAccessString( $str ) {
00186           $access = $this->getAccessKey();
00187           if ( !empty($access) && ( false !== ($pos = strpos($str, $access)) ) ) {
00188                return htmlspecialchars(substr($str, 0, $pos), ENT_QUOTES) . '<span style="text-decoration:underline">' . htmlspecialchars(substr($str, $pos, 1), ENT_QUOTES) . '</span>' . htmlspecialchars(substr($str, $pos+1), ENT_QUOTES);
00189           }
00190           return htmlspecialchars($str, ENT_QUOTES);
00191      }
00192 
00198      function setClass($class) {
00199           $class = trim($class);
00200           if ( !empty($class) ) {
00201             $this->_class[] = $class;
00202           }
00203      }
00209      function getClass() {
00210      if( empty($this->_class) ) return '';
00211      $class = array();
00212      foreach ($this->_class as $class) {
00213           $class[] = htmlspecialchars($class, ENT_QUOTES);
00214      }
00215           return implode(" ", $class);
00216      }
00217 
00223      function setCaption($caption) {
00224           $this->_caption = trim($caption);
00225      }
00226 
00233      function getCaption($encode = false) {
00234           return $encode ? htmlspecialchars($this->_caption, ENT_QUOTES) : $this->_caption;
00235      }
00236 
00242      function setDescription($description) {
00243           $this->_description = trim($description);
00244      }
00245 
00252      function getDescription($encode = false) {
00253           return $encode ? htmlspecialchars($this->_description, ENT_QUOTES) : $this->_description;
00254      }
00255 
00260      function setHidden() {
00261           $this->_hidden = true;
00262      }
00263 
00269      function isHidden() {
00270           return $this->_hidden;
00271      }
00272 
00278      function isRequired() {
00279           return $this->_required;
00280      }
00281 
00292      function setExtra($extra, $replace = false) {
00293           if ( $replace) {
00294                $this->_extra = array( trim($extra) );
00295           } else {
00296                $this->_extra[] = trim($extra);
00297           }
00298           return $this->_extra;
00299      }
00300 
00307      function getExtra($encode = false) {
00308      if (!$encode) {
00309           return implode(' ', $this->_extra);
00310      }
00311      $value = array();
00312      foreach ($this->_extra as $val) {
00313               $value[] = str_replace('>', '&gt;', str_replace('<', '&lt;', $val));
00314      }
00315      return empty($value) ? "" : " ".implode(' ', $value);
00316      }
00317 
00323      function renderValidationJS() {
00324      // render custom validation code if any
00325           if ( !empty( $this->customValidationCode ) ) {
00326                return implode( "\n", $this->customValidationCode );
00327           // generate validation code if required 
00328           } elseif ($this->isRequired()) {
00329                $eltname    = $this->getName();
00330                $eltcaption = $this->getCaption();
00331                $eltmsg = empty($eltcaption) ? sprintf( _FORM_ENTER, $eltname ) : sprintf( _FORM_ENTER, $eltcaption );
00332                $eltmsg = str_replace('"', '\"', stripslashes( $eltmsg ) );
00333                return "if ( myform.{$eltname}.value == \"\" ) { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }";
00334           }
00335           return ''; 
00336      }
00337 
00344      function render(){
00345      }
00346 }
00347 ?>

Generated on Sun Feb 17 00:55:40 2008 for XOOPS by  doxygen 1.5.5