20 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
37 var $customValidationCode = array();
70 var $_class = array();
84 var $_extra = array();
91 var $_required =
false;
98 var $_description =
'';
114 var $_nocolspan =
false;
126 function XoopsFormElement()
128 exit(
'This class cannot be instantiated!');
136 function isContainer()
146 function setName($name)
148 $this->_name = trim($name);
157 function getName($encode =
true)
159 if (
false != $encode) {
160 return str_replace(
'&',
'&', htmlspecialchars($this->_name, ENT_QUOTES));
170 function setAccessKey($key)
172 $this->_accesskey = trim($key);
179 function getAccessKey()
181 return $this->_accesskey;
189 function getAccessString($str)
191 $access = $this->getAccessKey();
192 if (! empty($access) && (
false !== (
$pos = strpos($str, $access)))) {
193 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);
195 return htmlspecialchars($str, ENT_QUOTES);
203 function setClass($class)
205 $class = trim($class);
206 if (! empty($class)) {
207 $this->_class[] = $class;
217 if (empty($this->_class)) {
221 foreach($this->_class as $class) {
222 $classes[] = htmlspecialchars($class, ENT_QUOTES);
224 return implode(
' ', $classes);
232 function setCaption($caption)
234 $this->_caption = trim($caption);
243 function getCaption($encode =
false)
245 return $encode ? htmlspecialchars($this->_caption, ENT_QUOTES) : $this->_caption;
254 function getTitle($encode =
true)
256 if (strlen($this->_description) > 0) {
258 ? htmlspecialchars(strip_tags($this->_caption .
' - ' . $this->_description), ENT_QUOTES)
259 : strip_tags($this->_caption .
' - ' . $this->_description);
261 return $encode ? htmlspecialchars(strip_tags($this->_caption), ENT_QUOTES)
262 : strip_tags($this->_caption);
271 function setDescription($description)
273 $this->_description = trim($description);
282 function getDescription($encode =
false)
284 return $encode ? htmlspecialchars($this->_description, ENT_QUOTES) : $this->_description;
292 $this->_hidden =
true;
302 return $this->_hidden;
310 function isRequired()
312 return $this->_required;
325 function setExtra($extra, $replace =
false)
328 $this->_extra = array(trim($extra));
330 $this->_extra[] = trim($extra);
332 return $this->_extra;
341 function getExtra($encode =
false)
344 return ' ' . implode(
' ', $this->_extra);
347 foreach ($this->_extra as $val) {
348 $value[] = str_replace(
'>',
'>', str_replace(
'<',
'<', $val));
350 return empty($value) ?
'' :
' ' . implode(
' ', $value);
361 function setNocolspan($nocolspan =
true)
363 $this->_nocolspan = $nocolspan;
374 function getNocolspan()
376 return $this->_nocolspan;
387 function getFormType()
389 return $this->_formtype;
400 function setFormType($value =
'')
402 $this->_formtype = $value;
410 function renderValidationJS()
413 if (!empty($this->customValidationCode)) {
414 return implode(NWLINE, $this->customValidationCode);
416 }
else if ($this->isRequired() && $eltname = $this->getName()) {
418 $eltcaption = $this->getCaption();
420 $eltmsg = str_replace(array(
':' ,
'?' ,
'%'),
'', $eltmsg);
421 $eltmsg = str_replace(
'"',
'\"', stripslashes($eltmsg));
422 $eltmsg = strip_tags($eltmsg);
423 echo $this->getFormType();
424 switch ($this->getFormType()) {
426 return NWLINE .
"if ( !myform.{$eltname}.checked ) { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
429 return NWLINE .
"if ( myform.{$eltname}.value == \"\" ) { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";