00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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("&", "&", 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('>', '>', str_replace('<', '<', $val));
00314 }
00315 return empty($value) ? "" : " ".implode(' ', $value);
00316 }
00317
00323 function renderValidationJS() {
00324
00325 if ( !empty( $this->customValidationCode ) ) {
00326 return implode( "\n", $this->customValidationCode );
00327
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 ?>