当前位置: 首页>>代码示例>>PHP>>正文


PHP HTML_QuickForm_RuleRegistry类代码示例

本文整理汇总了PHP中HTML_QuickForm_RuleRegistry的典型用法代码示例。如果您正苦于以下问题:PHP HTML_QuickForm_RuleRegistry类的具体用法?PHP HTML_QuickForm_RuleRegistry怎么用?PHP HTML_QuickForm_RuleRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTML_QuickForm_RuleRegistry类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getValidationScript

    /**
     * Returns the client side validation script
     *
     * The code here was copied from HTML_QuickForm and slightly modified to run rules per-element
     *
     * @access    public
     * @return    string    Javascript to perform validation, empty string if no 'client' rules were added
     */
    function getValidationScript()
    {
        if (empty($this->_rules) || empty($this->_attributes['onsubmit'])) {
            return '';
        }
        include_once 'HTML/QuickForm/RuleRegistry.php';
        $registry =& HTML_QuickForm_RuleRegistry::singleton();
        $test = array();
        $js_escape = array("\r" => '\\r', "\n" => '\\n', "\t" => '\\t', "'" => "\\'", '"' => '\\"', '\\' => '\\\\');
        foreach ($this->_rules as $elementName => $rules) {
            foreach ($rules as $rule) {
                if ('client' == $rule['validation']) {
                    unset($element);
                    $dependent = isset($rule['dependent']) && is_array($rule['dependent']);
                    $rule['message'] = strtr($rule['message'], $js_escape);
                    if (isset($rule['group'])) {
                        $group =& $this->getElement($rule['group']);
                        // No JavaScript validation for frozen elements
                        if ($group->isFrozen()) {
                            continue 2;
                        }
                        $elements =& $group->getElements();
                        foreach (array_keys($elements) as $key) {
                            if ($elementName == $group->getElementName($key)) {
                                $element =& $elements[$key];
                                break;
                            }
                        }
                    } elseif ($dependent) {
                        $element = array();
                        $element[] =& $this->getElement($elementName);
                        foreach ($rule['dependent'] as $idx => $elName) {
                            $element[] =& $this->getElement($elName);
                        }
                    } else {
                        $element =& $this->getElement($elementName);
                    }
                    // No JavaScript validation for frozen elements
                    if (is_object($element) && $element->isFrozen()) {
                        continue 2;
                    } elseif (is_array($element)) {
                        foreach (array_keys($element) as $key) {
                            if ($element[$key]->isFrozen()) {
                                continue 3;
                            }
                        }
                    }
                    $test[$elementName][] = $registry->getValidationScript($element, $elementName, $rule);
                }
            }
        }
        $js = '
<script type="text/javascript">
//<![CDATA[
function qf_errorHandler(element, _qfMsg) {
  div = element.parentNode;
  if (_qfMsg != \'\') {
    span = document.createElement("span");
    span.className = "error";
    span.appendChild(document.createTextNode(_qfMsg.substring(3)));
    br = document.createElement("br");

    var errorDiv = document.getElementById(element.name + \'_errorDiv\');
    if (!errorDiv) {
      errorDiv = document.createElement("div");
      errorDiv.id = element.name + \'_errorDiv\';
    }
    while (errorDiv.firstChild) {
      errorDiv.removeChild(errorDiv.firstChild);
    }
    
    errorDiv.insertBefore(br, errorDiv.firstChild);
    errorDiv.insertBefore(span, errorDiv.firstChild);
    element.parentNode.insertBefore(errorDiv, element.parentNode.firstChild);

    if (div.className.substr(div.className.length - 6, 6) != " error"
        && div.className != "error") {
      div.className += " error";
    }

    return false;
  } else {
    var errorDiv = document.getElementById(element.name + \'_errorDiv\');
    if (errorDiv) {
      errorDiv.parentNode.removeChild(errorDiv);
    }

    if (div.className.substr(div.className.length - 6, 6) == " error") {
      div.className = div.className.substr(0, div.className.length - 6);
    } else if (div.className == "error") {
      div.className = "";
    }
//.........这里部分代码省略.........
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:101,代码来源:DHTMLRulesTableless.php

示例2: getValidationScript

    /**
     * Returns the client side validation script
     *
     * The code here was copied from HTML_QuickForm_DHTMLRulesTableless who copied it from  HTML_QuickForm
     * and slightly modified to run rules per-element
     * Needed to override this because of an error with client side validation of grouped elements.
     *
     * @return string Javascript to perform validation, empty string if no 'client' rules were added
     */
    function getValidationScript()
    {
        if (empty($this->_rules) || empty($this->_attributes['onsubmit'])) {
            return '';
        }
        include_once 'HTML/QuickForm/RuleRegistry.php';
        $registry =& HTML_QuickForm_RuleRegistry::singleton();
        $test = array();
        $js_escape = array("\r" => '\\r', "\n" => '\\n', "\t" => '\\t', "'" => "\\'", '"' => '\\"', '\\' => '\\\\');
        foreach ($this->_rules as $elementName => $rules) {
            foreach ($rules as $rule) {
                if ('client' == $rule['validation']) {
                    unset($element);
                    //TODO: find out how to properly initialize it
                    $dependent = isset($rule['dependent']) && is_array($rule['dependent']);
                    $rule['message'] = strtr($rule['message'], $js_escape);
                    if (isset($rule['group'])) {
                        $group =& $this->getElement($rule['group']);
                        // No JavaScript validation for frozen elements
                        if ($group->isFrozen()) {
                            continue 2;
                        }
                        $elements =& $group->getElements();
                        foreach (array_keys($elements) as $key) {
                            if ($elementName == $group->getElementName($key)) {
                                $element =& $elements[$key];
                                break;
                            }
                        }
                    } elseif ($dependent) {
                        $element = array();
                        $element[] =& $this->getElement($elementName);
                        foreach ($rule['dependent'] as $elName) {
                            $element[] =& $this->getElement($elName);
                        }
                    } else {
                        $element =& $this->getElement($elementName);
                    }
                    // No JavaScript validation for frozen elements
                    if (is_object($element) && $element->isFrozen()) {
                        continue 2;
                    } elseif (is_array($element)) {
                        foreach (array_keys($element) as $key) {
                            if ($element[$key]->isFrozen()) {
                                continue 3;
                            }
                        }
                    }
                    //for editor element, [text] is appended to the name.
                    $fullelementname = $elementName;
                    if ($element->getType() == 'editor') {
                        $fullelementname .= '[text]';
                        //Add format to rule as moodleform check which format is supported by browser
                        //it is not set anywhere... So small hack to make sure we pass it down to quickform
                        if (is_null($rule['format'])) {
                            $rule['format'] = $element->getFormat();
                        }
                    }
                    // Fix for bug displaying errors for elements in a group
                    $test[$fullelementname][0][] = $registry->getValidationScript($element, $fullelementname, $rule);
                    $test[$fullelementname][1] = $element;
                    //end of fix
                }
            }
        }
        // Fix for MDL-9524. If you don't do this, then $element may be left as a reference to one of the fields in
        // the form, and then that form field gets corrupted by the code that follows.
        unset($element);
        $js = '
<script type="text/javascript">
//<![CDATA[

var skipClientValidation = false;

function qf_errorHandler(element, _qfMsg) {
  div = element.parentNode;

  if ((div == undefined) || (element.name == undefined)) {
    //no checking can be done for undefined elements so let server handle it.
    return true;
  }

  if (_qfMsg != \'\') {
    var errorSpan = document.getElementById(\'id_error_\'+element.name);
    if (!errorSpan) {
      errorSpan = document.createElement("span");
      errorSpan.id = \'id_error_\'+element.name;
      errorSpan.className = "error";
      element.parentNode.insertBefore(errorSpan, element.parentNode.firstChild);
      document.getElementById(errorSpan.id).setAttribute(\'TabIndex\', \'0\');
      document.getElementById(errorSpan.id).focus();
//.........这里部分代码省略.........
开发者ID:educacionbe,项目名称:cursos,代码行数:101,代码来源:formslib.php

示例3: getValidationScript

    /**
     * Returns the client side validation script
     *
     * The code here was copied from HTML_QuickForm_DHTMLRulesTableless who copied it from  HTML_QuickForm
     * and slightly modified to run rules per-element
     * Needed to override this because of an error with client side validation of grouped elements.
     *
     * @access    public
     * @return    string    Javascript to perform validation, empty string if no 'client' rules were added
     */
    function getValidationScript()
    {
        if (empty($this->_rules) || empty($this->_attributes['onsubmit'])) {
            return '';
        }
        include_once 'HTML/QuickForm/RuleRegistry.php';
        $registry =& HTML_QuickForm_RuleRegistry::singleton();
        $test = array();
        $js_escape = array("\r" => '\\r', "\n" => '\\n', "\t" => '\\t', "'" => "\\'", '"' => '\\"', '\\' => '\\\\');
        foreach ($this->_rules as $elementName => $rules) {
            foreach ($rules as $rule) {
                if ('client' == $rule['validation']) {
                    unset($element);
                    //TODO: find out how to properly initialize it
                    $dependent = isset($rule['dependent']) && is_array($rule['dependent']);
                    $rule['message'] = strtr($rule['message'], $js_escape);
                    if (isset($rule['group'])) {
                        $group =& $this->getElement($rule['group']);
                        // No JavaScript validation for frozen elements
                        if ($group->isFrozen()) {
                            continue 2;
                        }
                        $elements =& $group->getElements();
                        foreach (array_keys($elements) as $key) {
                            if ($elementName == $group->getElementName($key)) {
                                $element =& $elements[$key];
                                break;
                            }
                        }
                    } elseif ($dependent) {
                        $element = array();
                        $element[] =& $this->getElement($elementName);
                        foreach ($rule['dependent'] as $elName) {
                            $element[] =& $this->getElement($elName);
                        }
                    } else {
                        $element =& $this->getElement($elementName);
                    }
                    // No JavaScript validation for frozen elements
                    if (is_object($element) && $element->isFrozen()) {
                        continue 2;
                    } elseif (is_array($element)) {
                        foreach (array_keys($element) as $key) {
                            if ($element[$key]->isFrozen()) {
                                continue 3;
                            }
                        }
                    }
                    // Fix for bug displaying errors for elements in a group
                    //$test[$elementName][] = $registry->getValidationScript($element, $elementName, $rule);
                    $test[$elementName][0][] = $registry->getValidationScript($element, $elementName, $rule);
                    $test[$elementName][1] = $element;
                    //end of fix
                }
            }
        }
        // Fix for MDL-9524. If you don't do this, then $element may be left as a reference to one of the fields in
        // the form, and then that form field gets corrupted by the code that follows.
        unset($element);
        $js = '
<script type="text/javascript">
//<![CDATA[

var skipClientValidation = false;

function qf_errorHandler(element, _qfMsg) {
  div = element.parentNode;
  if (_qfMsg != \'\') {
    var errorSpan = document.getElementById(\'id_error_\'+element.name);
    if (!errorSpan) {
      errorSpan = document.createElement("span");
      errorSpan.id = \'id_error_\'+element.name;
      errorSpan.className = "error";
      element.parentNode.insertBefore(errorSpan, element.parentNode.firstChild);
    }

    while (errorSpan.firstChild) {
      errorSpan.removeChild(errorSpan.firstChild);
    }

    errorSpan.appendChild(document.createTextNode(_qfMsg.substring(3)));
    errorSpan.appendChild(document.createElement("br"));

    if (div.className.substr(div.className.length - 6, 6) != " error"
        && div.className != "error") {
      div.className += " error";
    }

    return false;
  } else {
//.........这里部分代码省略.........
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:101,代码来源:formslib.php

示例4: getValidationScript

 /**
  * Returns the client side validation script
  *
  * @since     2.0
  * @access    public
  * @return    string    Javascript to perform validation, empty string if no 'client' rules were added
  */
 function getValidationScript()
 {
     if (empty($this->_rules) || empty($this->_attributes['onsubmit'])) {
         return '';
     }
     include_once 'HTML/QuickForm/RuleRegistry.php';
     $registry =& HTML_QuickForm_RuleRegistry::singleton();
     $test = array();
     $js_escape = array("\r" => '\\r', "\n" => '\\n', "\t" => '\\t', "'" => "\\'", '"' => '\\"', '\\' => '\\\\');
     foreach ($this->_rules as $elementName => $rules) {
         foreach ($rules as $rule) {
             if ('client' == $rule['validation']) {
                 unset($element);
                 $dependent = isset($rule['dependent']) && is_array($rule['dependent']);
                 $rule['message'] = strtr($rule['message'], $js_escape);
                 if (isset($rule['group'])) {
                     $group =& $this->getElement($rule['group']);
                     // No JavaScript validation for frozen elements
                     if ($group->isFrozen()) {
                         continue 2;
                     }
                     $elements =& $group->getElements();
                     foreach (array_keys($elements) as $key) {
                         if ($elementName == $group->getElementName($key)) {
                             $element =& $elements[$key];
                             break;
                         }
                     }
                 } elseif ($dependent) {
                     $element = array();
                     $element[] =& $this->getElement($elementName);
                     foreach ($rule['dependent'] as $elName) {
                         $element[] =& $this->getElement($elName);
                     }
                 } else {
                     $element =& $this->getElement($elementName);
                 }
                 // No JavaScript validation for frozen elements
                 if (is_object($element) && $element->isFrozen()) {
                     continue 2;
                 } elseif (is_array($element)) {
                     foreach (array_keys($element) as $key) {
                         if ($element[$key]->isFrozen()) {
                             continue 3;
                         }
                     }
                 }
                 $test[] = $registry->getValidationScript($element, $elementName, $rule);
             }
         }
     }
     if (count($test) > 0) {
         return "\n<script type=\"text/javascript\">\n" . "//<![CDATA[\n" . "function validate_" . $this->_attributes['id'] . "(frm) {\n" . "  var value = '';\n" . "  var errFlag = new Array();\n" . "  var _qfGroups = {};\n" . "  _qfMsg = '';\n\n" . join("\n", $test) . "\n  if (_qfMsg != '') {\n" . "    _qfMsg = '" . strtr($this->_jsPrefix, $js_escape) . "' + _qfMsg;\n" . "    _qfMsg = _qfMsg + '\\n" . strtr($this->_jsPostfix, $js_escape) . "';\n" . "    alert(_qfMsg);\n" . "    return false;\n" . "  }\n" . "  return true;\n" . "}\n" . "//]]>\n" . "</script>";
     }
     return '';
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:63,代码来源:QuickForm.php

示例5: getValidationScript

    /**
     * Returns the client side validation script
     *
     * The code here was copied from HTML_QuickForm and slightly modified to run rules per-element
     *
     * @access    public
     * @return    string    Javascript to perform validation, empty string if no 'client' rules were added
     */
    function getValidationScript()
    {
        if (empty($this->_rules) || empty($this->_attributes['onsubmit'])) {
            return '';
        }
        include_once 'HTML/QuickForm/RuleRegistry.php';
        $registry =& HTML_QuickForm_RuleRegistry::singleton();
        $test = array();
        $js_escape = array("\r" => '\\r', "\n" => '\\n', "\t" => '\\t', "'" => "\\'", '"' => '\\"', '\\' => '\\\\');
        foreach ($this->_rules as $elementName => $rules) {
            foreach ($rules as $rule) {
                if ('client' == $rule['validation']) {
                    unset($element);
                    $dependent = isset($rule['dependent']) && is_array($rule['dependent']);
                    $rule['message'] = strtr($rule['message'], $js_escape);
                    if (isset($rule['group'])) {
                        $group =& $this->getElement($rule['group']);
                        // No JavaScript validation for frozen elements
                        if ($group->isFrozen()) {
                            continue 2;
                        }
                        $elements =& $group->getElements();
                        foreach (array_keys($elements) as $key) {
                            if ($elementName == $group->getElementName($key)) {
                                $element =& $elements[$key];
                                break;
                            }
                        }
                    } elseif ($dependent) {
                        $element = array();
                        $element[] =& $this->getElement($elementName);
                        foreach ($rule['dependent'] as $idx => $elName) {
                            $element[] =& $this->getElement($elName);
                        }
                    } else {
                        $element =& $this->getElement($elementName);
                    }
                    // No JavaScript validation for frozen elements
                    if (is_object($element) && $element->isFrozen()) {
                        continue 2;
                    } elseif (is_array($element)) {
                        foreach (array_keys($element) as $key) {
                            if ($element[$key]->isFrozen()) {
                                continue 3;
                            }
                        }
                    }
                    $test[$elementName][] = $registry->getValidationScript($element, $elementName, $rule);
                }
            }
        }
        $js = '
<script type="text/javascript"><!--//--><![CDATA[//><!--
qf_errorHandler = function(element, _qfMsg) {
  div = element.parentNode;
  var elementName = element.name.replace(/\\[/, "_____");
  var elementName = elementName.replace(/\\]/, "_____");
  if (_qfMsg != \'\') {
    span = document.createElement("span");
    span.className = "error";
    _qfMsg = _qfMsg.substring(4);
    span.appendChild(document.createTextNode(_qfMsg));
    br = document.createElement("br");

    var errorDiv = document.getElementById(elementName + \'_errorDiv\');
    if (!errorDiv) {
      errorDiv = document.createElement("div");
      errorDiv.id = elementName + \'_errorDiv\';
    } else {
      if (   div.firstChild.textContent == \'\'
          || _qfMsg == div.firstChild.textContent
         ) {
        return false;
      }
    }
    while (errorDiv.firstChild) {
      errorDiv.removeChild(errorDiv.firstChild);
    }

    errorDiv.insertBefore(br, errorDiv.firstChild);
    errorDiv.insertBefore(span, errorDiv.firstChild);

    errorDivInserted = false;
    for (var i = element.parentNode.childNodes.length - 1; i >= 0; i--) {
      j = i - 1;
      if (j >= 0 && element.parentNode.childNodes[j].nodeName == "DIV") {
        element.parentNode.insertBefore(errorDiv, element.parentNode.childNodes[i]);
        errorDivInserted = true;
        break;
      }
    }
    if (!errorDivInserted) {
//.........这里部分代码省略.........
开发者ID:bobah,项目名称:acbdb,代码行数:101,代码来源:PageDHTMLRulesTableless.php


注:本文中的HTML_QuickForm_RuleRegistry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。