Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Change quickform custom addrule returns #6332

Merged
merged 2 commits into from
May 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions www/lib/HTML/QuickForm/HTML_QuickFormCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ public function addRule($element, $message, $type, $format=null, $validation='se
if (!$force) {
if (!is_array($element) && !$this->elementExists($element)) {
trigger_error("Element '$element' does not exist");
return;
} elseif (is_array($element)) {
foreach ($element as $el) {
if (!$this->elementExists($el)) {
trigger_error("Element '$el' does not exist");
return;
}
}
}
Expand Down Expand Up @@ -199,6 +201,42 @@ public function addRule($element, $message, $type, $format=null, $validation='se
);
}


/**
* Applies a data filter for the given field(s)
*
* @param mixed $element Form element name or array of such names
* @param mixed $filter Callback, either function name or array(&$object, 'method')
* @throws HTML_QuickForm_Error
*/
public function applyFilter($element, $filter)
{
if (!is_callable($filter)) {
trigger_error("Callback function '$filter' does not exist");
}
if ($element == '__ALL__') {
$this->_submitValues = $this->_recursiveFilter($filter, $this->_submitValues);
} else {
if (!is_array($element)) {
$element = array($element);
}
foreach ($element as $elName) {
$value = $this->getSubmitValue($elName);
if (null !== $value) {
if (false === strpos($elName, '[')) {
$this->_submitValues[$elName] = $this->_recursiveFilter($filter, $value);
} else {
$idx = "['" . str_replace(
array('\\', '\'', ']', '['), array('\\\\', '\\\'', '', "']['"),
$elName
) . "']";
eval("\$this->_submitValues{$idx} = \$this->_recursiveFilter(\$filter, \$value);");
}
}
}
}
}

/**
* Add additional custom element types to $GLOBALS
*/
Expand Down