1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687:
<?php
defined('ICMS_ROOT_PATH') or die("ImpressCMS root path not defined");
class icms_ipf_form_Base extends icms_form_Theme {
public $targetObject = NULL;
public $form_fields = NULL;
private $_cancel_js_action = FALSE;
private $_custom_button = FALSE;
private $_captcha = FALSE;
private $_form_name = FALSE;
private $_form_caption = FALSE;
private $_submit_button_caption = FALSE;
public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = NULL, $submit_button_caption = FALSE, $cancel_js_action = FALSE, $captcha = FALSE) {
$this->targetObject =& $target;
$this->form_fields = $form_fields;
$this->_cancel_js_action = $cancel_js_action;
$this->_captcha = $captcha;
$this->_form_name = $form_name;
$this->_form_caption = $form_caption;
$this->_submit_button_caption = $submit_button_caption;
if (!isset($form_action)) {
$form_action = xoops_getenv('SCRIPT_NAME');
}
parent::__construct( $form_caption , $form_name, $form_action);
$this->setExtra('enctype="multipart/form-data"');
$this->createElements();
$this->createPermissionControls();
}
public function addCustomButton($name, $caption, $onclick = FALSE) {
$custom_button_array = array(
'name' => $name,
'caption' => $caption,
'onclick' => $onclick
);
$this->_custom_button[] = $custom_button_array;
}
public function addElement(&$formElement, $key = FALSE, $var = FALSE, $required = 'notset'){
if ($key) {
if ($this->targetObject->vars[$key]['readonly']) {
$formElement->setExtra('disabled="disabled"');
$formElement->setName($key . '-readonly');
$hidden = new icms_form_elements_Hidden($key, $this->targetObject->vars[$key]['value']);
$this->addElement($hidden);
}
$formElement->setDescription($var['form_dsc']);
if (isset($this->targetObject->controls[$key]['onSelect'])) {
$hidden = new icms_form_elements_Hidden('changedField', FALSE);
$this->addElement($hidden);
$otherExtra = isset($var['form_extra']) ? $var['form_extra'] : '';
$onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
$formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
} else {
if (isset($var['form_extra'])) {
$formElement->setExtra($var['form_extra']);
}
}
$controls = $this->targetObject->controls;
if(isset($controls[$key]['js'])){
$formElement->customValidationCode[] = $controls[$key]['js'];
}
parent::addElement($formElement, $required == 'notset' ? $var['required'] : $required);
} else {
parent::addElement($formElement, $required == 'notset' ? FALSE : TRUE);
}
unset($formElement);
}
private function createElements() {
$controls = $this->targetObject->controls;
$vars = $this->targetObject->vars;
foreach ($vars as $key=>$var) {
if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) {
$elementToAdd = new icms_form_elements_Hidden($key, $var['value']);
$this->addElement($elementToAdd, $key, $var, FALSE);
unset($elementToAdd);
} else {
if ($key == 'parentid') {
}
if (isset($controls[$key])) {
if (!isset($controls[$key]['name']) || !$controls[$key]['name']) {
$controls[$key]['name'] = 'select';
}
$form_select = $this->getControl($controls[$key]['name'], $key);
$this->addElement($form_select, $key, $var);
unset($form_select);
} else {
switch ($var['data_type']) {
case XOBJ_DTYPE_TXTBOX:
$form_text = $this->getControl("text", $key);
$this->addElement($form_text, $key, $var);
unset($form_text);
break;
case XOBJ_DTYPE_INT:
$this->targetObject->setControl($key, array('name' => 'text', 'size' => '5'));
$form_text = $this->getControl("text", $key);
$this->addElement($form_text, $key, $var);
unset($form_text);
break;
case XOBJ_DTYPE_FLOAT:
$this->targetObject->setControl($key, array('name' => 'text', 'size' => '5'));
$form_text = $this->getControl("text", $key);
$this->addElement($form_text, $key, $var);
unset($form_text);
break;
case XOBJ_DTYPE_LTIME:
$form_datetime = $this->getControl('datetime', $key);
$this->addElement($form_datetime, $key, $var);
unset($form_datetime);
break;
case XOBJ_DTYPE_STIME:
$form_date = $this->getControl('date', $key);
$this->addElement($form_date, $key, $var);
unset($form_date);
break;
case XOBJ_DTYPE_TIME_ONLY:
$form_time = $this->getControl('time', $key);
$this->addElement($form_time, $key, $var);
unset($form_time);
break;
case XOBJ_DTYPE_CURRENCY:
$this->targetObject->setControl($key, array('name' => 'text', 'size' => '15'));
$form_currency = $this->getControl("text", $key);
$this->addElement($form_currency, $key, $var);
unset($form_currency);
break;
case XOBJ_DTYPE_URLLINK:
$form_urllink = $this->getControl("urllink", $key);
$this->addElement($form_urllink, $key, $var);
unset($form_urllink);
break;
case XOBJ_DTYPE_FILE:
$form_file = $this->getControl("richfile", $key);
$this->addElement($form_file, $key, $var);
unset($form_file);
break;
case XOBJ_DTYPE_TXTAREA:
$form_text_area = $this->getControl('textarea', $key);
$this->addElement($form_text_area, $key, $var);
unset($form_text_area);
break;
case XOBJ_DTYPE_ARRAY:
break;
case XOBJ_DTYPE_SOURCE:
$form_source_editor = $this->getControl('source', $key);
$this->addElement($form_source_editor, $key, $var);
unset($form_source_editor);
break;
case XOBJ_DTYPE_FORM_SECTION:
$section_control = $this->getControl('section', $key);
$this->addElement($section_control, $key, $var);
unset($section_control);
break;
case XOBJ_DTYPE_FORM_SECTION_CLOSE:
$this->targetObject->setControl($key, array("close" => TRUE));
$section_control = $this->getControl('section', $key);
$this->addElement($section_control, $key, $var);
unset($section_control);
break;
}
}
}
}
$this->addElement(new icms_form_elements_Hidden('icms_page_before_form', icms_get_page_before_form()));
}
private function createPermissionControls() {
$icmsModuleConfig = $this->targetObject->handler->getModuleConfig();
$permissions = $this->targetObject->handler->getPermissions();
if ($permissions) {
$member_handler = icms::handler('icms_member');
$group_list = $member_handler->getGroupList();
asort($group_list);
foreach($permissions as $permission) {
$groups_value = FALSE;
if ($this->targetObject->isNew()) {
if (isset($icmsModuleConfig['def_perm_' . $permission['perm_name']])) {
$groups_value = $icmsModuleConfig['def_perm_' . $permission['perm_name']];
}
} else {
$groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
}
$groups_select = new icms_form_elements_Select($permission['caption'], $permission['perm_name'], $groups_value, 4, TRUE);
$groups_select->setDescription($permission['description']);
$groups_select->addOptionArray($group_list);
$this->addElement($groups_select);
unset($groups_select);
}
}
}
private function createButtons($form_name, $form_caption, $submit_button_caption = FALSE) {
$button_tray = new icms_form_elements_Tray('', '');
$button_tray->addElement(new icms_form_elements_Hidden('op', $form_name));
if (!$submit_button_caption) {
if ($this->targetObject->isNew()) {
$butt_create = new icms_form_elements_Button('', 'create_button', _CO_ICMS_CREATE, 'submit');
} else {
$butt_create = new icms_form_elements_Button('', 'modify_button', _CO_ICMS_MODIFY, 'submit');
}
} else {
$butt_create = new icms_form_elements_Button('', 'modify_button', $submit_button_caption , 'submit');
}
$butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
$button_tray->addElement($butt_create);
if ($this->_custom_button) {
foreach($this->_custom_button as $custom_button) {
$butt_custom = new icms_form_elements_Button('', $custom_button['name'], $custom_button['caption'], 'submit');
if ($custom_button['onclick']) {
$butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
}
$button_tray->addElement($butt_custom);
unset($butt_custom);
}
}
$butt_cancel = new icms_form_elements_Button('', 'cancel_button', _CO_ICMS_CANCEL, 'button');
if ($this->_cancel_js_action) {
$butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
} else {
$butt_cancel->setExtra('onclick="history.go(-1)"');
}
$button_tray->addElement($butt_cancel);
$this->addElement($button_tray);
}
private function getControl($controlName, $key) {
switch ($controlName) {
case 'color':
$control = $this->targetObject->getControl($key);
$controlObj = new icms_form_elements_Colorpicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
return $controlObj;
break;
case 'label':
return new icms_form_elements_Label($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key));
break;
case 'textarea' :
$form_rows = isset($this->targetObject->controls[$key]['rows']) ? $this->targetObject->controls[$key]['rows'] : 5;
$form_cols = isset($this->targetObject->controls[$key]['cols']) ? $this->targetObject->controls[$key]['cols'] : 60;
$editor = new icms_form_elements_Textarea($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols);
if ($this->targetObject->vars[$key]['form_dsc']) {
$editor->setDescription($this->targetObject->vars[$key]['form_dsc']);
}
return $editor;
break;
case 'dhtmltextarea' :
$editor = new icms_form_elements_Dhtmltextarea($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 15, 50);
if ($this->targetObject->vars[$key]['form_dsc']) {
$editor->setDescription($this->targetObject->vars[$key]['form_dsc']);
}
return $editor;
break;
case 'theme':
return $this->getThemeSelect($key, $this->targetObject->vars[$key]);
break;
case 'theme_multi':
return $this->getThemeSelect($key, $this->targetObject->vars[$key], TRUE);
break;
case 'timezone':
return new icms_form_elements_select_Timezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
break;
case 'group':
return new icms_form_elements_select_Group($this->targetObject->vars[$key]['form_caption'], $key, FALSE, $this->targetObject->getVar($key, 'e'), 1, FALSE);
break;
case 'group_multi':
return new icms_form_elements_select_Group($this->targetObject->vars[$key]['form_caption'], $key, FALSE, $this->targetObject->getVar($key, 'e'), 5, TRUE);
break;
case 'user_multi':
return new icms_form_elements_select_User($this->targetObject->vars[$key]['form_caption'], $key, FALSE, $this->targetObject->getVar($key, 'e'), 5, TRUE);
break;
case 'password':
return new icms_form_elements_Password($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e'));
break;
case 'country':
return new icms_form_elements_select_Country($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'));
break;
case 'sourceeditor':
icms_core_Debug::setDeprecated('icms_ipf_form_elements_Source', sprintf(_CORE_REMOVE_IN_VERSION, '1.4'));
$controlName = "source";
default:
$classname = "icms_ipf_form_elements_" . ucfirst($controlName);
if (!class_exists($classname)) {
$classname = "IcmsForm" . ucfirst($controlName) . "Element";
if (!class_exists($classname)) {
if (file_exists(ICMS_ROOT_PATH . "/class/icmsform/elements/" . strtolower($classname) . ".php")) {
include_once ICMS_ROOT_PATH . "/class/icmsform/elements/" . strtolower($classname) . ".php" ;
} else {
$moduleName = $this->targetObject->handler->_moduleName;
if ($moduleName != 'system') {
$moduleFormElementsPath = $this->targetObject->handler->_modulePath . "/class/form/elements/";
} else {
$moduleFormElementsPath = $this->targetObject->handler->_modulePath . "/admin/{$name}/class/form/elements/";
}
$classname = ucfirst($moduleName) . ucfirst($controlName) . "Element";
$classFileName = strtolower($classname) . ".php";
if (file_exists($moduleFormElementsPath . $classFileName)) {
include_once $moduleFormElementsPath . $classFileName ;
} else {
trigger_error($classname . " not found", E_USER_WARNING);
return new icms_form_elements_Label();
}
}
}
}
return new $classname($this->targetObject, $key);
break;
}
}
private function getThemeSelect($key, $var, $multiple=FALSE) {
$size = $multiple ? 5 : 1;
$theme_select = new icms_form_elements_Select($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
$handle = opendir(ICMS_THEME_PATH . "/");
$dirlist = array();
while (FALSE !== ($file = readdir($handle))) {
if (is_dir(ICMS_THEME_PATH . "/" . $file) && !preg_match("/^[.]{1,2}$/",$file) && strtolower($file) != 'cvs') {
$dirlist[$file] = $file;
}
}
closedir($handle);
if (!empty($dirlist)) {
asort($dirlist);
$theme_select->addOptionArray($dirlist);
}
return $theme_select;
}
public function &getElementById($keyname) {
foreach ($this->_elements as $eleObj) {
if ($eleObj->getName() == $keyname) {
$ret =& $eleObj;
break;
}
}
return isset($ret) ? $ret : FALSE;
}
public function render() {
$this->createButtons($this->_form_name, $this->_form_caption, $this->_submit_button_caption);
$required =& $this->getRequired();
$ret = "
<form name='".$this->getName()."_dorga' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra().">
<table width='100%' class='outer' cellspacing='1'>
<tr><th colspan='2'>".$this->getTitle()."</th></tr>
";
$hidden = '';
$class = 'even';
foreach ($this->getElements() as $ele) {
if (!is_object($ele)) {
$ret .= $ele;
} elseif (!$ele->isHidden()) {
if (get_class($ele) == 'icms_ipf_form_elements_Section' && !$ele->isClosingSection()) {
$ret .= '<tr><th colspan="2">' . $ele->render() . '</th></tr>';
} elseif (get_class($ele) == 'icms_ipf_form_elements_Section' && $ele->isClosingSection()) {
$ret .= '<tr><td class="even" colspan="2"> </td></tr>';
} else {
$ret .= "<tr id='" . $ele->getName() . "_row' valign='top' align='"._GLOBAL_LEFT."'><td class='head'>".$ele->getCaption();
if ($ele->getDescription() != '') {
$ret .= '<br /><br /><span style="font-weight: normal;">'.$ele->getDescription().'</span>';
}
$ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n";
}
} else {
$hidden .= $ele->render();
}
}
$ret .= "</table>\n$hidden\n</form>\n";
$ret .= $this->renderValidationJS(TRUE);
return $ret;
}
public function assign(&$tpl, $smartyName = FALSE){
$this->createButtons($this->_form_name, $this->_form_caption, $this->_submit_button_caption);
$i = 0;
$elements = array();
foreach ($this->getElements() as $ele) {
$n = ($ele->getName() != "") ? $ele->getName() : $i;
$elements[$n]['name'] = $ele->getName();
$elements[$n]['caption'] = $ele->getCaption();
$elements[$n]['body'] = $ele->render();
$elements[$n]['hidden'] = $ele->isHidden();
$elements[$n]['required'] = $ele->isRequired();
$elements[$n]['section'] = get_class($ele) == 'icms_ipf_form_elements_Section' && !$ele->isClosingSection();
$elements[$n]['section_close'] = get_class($ele) == 'icms_ipf_form_elements_Section' && $ele->isClosingSection();
$elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : FALSE;
if ($ele->getDescription() != '') {
$elements[$n]['description'] = $ele->getDescription();
}
$i++;
}
$js = $this->renderValidationJS();
if (!$smartyName) {
$smartyName = $this->getName();
}
$tpl->assign($smartyName, array('title' => $this->getTitle(), 'name' => $this->getName(), 'action' => $this->getAction(), 'method' => $this->getMethod(), 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), 'javascript' => $js, 'elements' => $elements));
}
public function renderValidationJS($withtags = TRUE) {
$js = "";
if ($withtags) {
$js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
}
$formname = $this->getName();
$js .= "function xoopsFormValidate_{$formname}(myform) {";
$elements = $this->getRequired();
foreach ($elements as $elt) {
$eltname = $elt->getName();
$eltcaption = trim($elt->getCaption());
$eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
$eltmsg = str_replace('"', '\"', stripslashes($eltmsg));
if (strtolower(get_class($elt)) == 'icms_form_elements_Radio') {
$js .= "var myOption = -1;";
$js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) {
if (myform.{$eltname}[i].checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n";
} elseif (strtolower(get_class($elt)) == 'icms_ipf_form_elements_selectmulti' ||
strtolower(get_class($elt)) == 'icmsformselect_multielement') {
$js .= "var hasSelections = FALSE;";
$js .= "for(var i = 0; i < myform['{$eltname}[]'].length; i++){
if (myform['{$eltname}[]'].options[i].selected) {
hasSelections = TRUE;
}
}
if (hasSelections == FALSE) {
window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n";
} elseif (strtolower(get_class($elt)) == 'icms_form_elements_Checkbox') {
$js .= "var hasSelections = FALSE;";
if (strpos($eltname, '[') === FALSE) {
$js .= "for(var i = 0; i < myform['{$eltname}[]'].length; i++){
if (myform['{$eltname}[]'][i].checked) {
hasSelections = TRUE;
}
}
if (hasSelections == FALSE) {
window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n";
} else {
$js .= "for(var i = 0; i < myform['{$eltname}'].length; i++){
if (myform['{$eltname}'][i].checked) {
hasSelections = TRUE;
}
}
if (hasSelections == FALSE) {
window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
}
} else {
$js .= "if ( myform.{$eltname}.value == \"\" ) "
. "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
}
}
$elements = $this->getElements(TRUE);
foreach ($elements as $elt) {
if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) != 'icms_form_elements_Checkbox') {
if ($eltjs = $elt->renderValidationJS()) {
$js .= $eltjs . "\n";
}
}
}
$js .= "return true;\n}\n";
if ($withtags) {
$js .= "//--></script>\n<!-- End Form Vaidation JavaScript //-->\n";
}
return $js;
}
public function renderValidationJS2($withtags = TRUE) {
global $xoTheme;
$rules = $titles = '';
$elements = $this->getRequired();
foreach ($elements as $elt) {
if(!empty($rules))
$rules .= ",";
$rules .= '\''.$elt->getName().'\': { required: TRUE }';
if(!empty($titles))
$titles .= ",";
$titles .= $elt->getName().': "'._REQUIRED.'"';
}
$xoTheme->addScript('', array('type' => 'text/javascript'), 'alert($());$().ready(function() { $("#'.$this->getName().'").validate({
rules: {
'.$rules.'
},
messages: {
'.$titles.'
}
})});');
}
}