Commit 04d3eafe authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractBuildForm / Save: moved inputCheckPattern[] to OnArray Class.

parent 028b35ab
......@@ -19,6 +19,7 @@ require_once(__DIR__ . '/../qfq/exceptions/UserException.php');
require_once(__DIR__ . '/../qfq/Database.php');
require_once(__DIR__ . '/../qfq/helper/HelperFormElement.php');
require_once(__DIR__ . '/../qfq/helper/Support.php');
require_once(__DIR__ . '/../qfq/helper/OnArray.php');
/**
......@@ -86,12 +87,7 @@ abstract class AbstractBuildForm {
'pill' => 'Pill'
];
$this->inputCheckPattern = [
'min|max' => 'min="%s"|max="%s"',
'pattern' => 'pattern="%s"',
'number' => 'pattern="^[0-9]*$"',
'email' => 'pattern="^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"'
];
$this->inputCheckPattern = OnArray::inputCheckPatternArray();
}
......@@ -209,6 +205,8 @@ abstract class AbstractBuildForm {
* @throws DbException
*/
public function getActionUrl() {
return 'typo3conf/ext/qfq/qfq/api/save.php';
$queryStringArray = array();
Support::appendTypo3ParameterToArray($queryStringArray);
......@@ -1059,18 +1057,18 @@ abstract class AbstractBuildForm {
if (isset($formElement['detail'])) {
$detailParam = KeyValueStringParser::parse($formElement['detail']);
foreach ($detailParam as $src => $dest) {
// Constants
if ($src[0] == '#') {
$queryStringArray[$dest] = substr($src, 1);
continue;
}
// Form record values or parameter
if (isset($record[$src])) {
$queryStringArray[$dest] = $record[$src];
}
}
}
Support::appendTypo3ParameterToArray($queryStringArray);
// If there is a specific targetpage defined, take it.
if (isset($formElement['page']) && $formElement['page'] !== '') {
......
......@@ -45,6 +45,8 @@ class Save {
}
/**
* Starts save process. On succcess, returns forwardmode/page.
*
* @throws CodeException
* @throws DbException
* @throws UserException
......@@ -140,14 +142,17 @@ class Save {
$pattern = '';
$minMax = array();
$this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'], STORE_SYSTEM);
switch ($formElement['checkType']) {
case 'min|max':
$valueCompare = $value;
$minMax = explode('|', $formElement['checkPattern']);
if ($minMax[0] === '' || $minMax[1] === '')
throw new UserException('Missing value for min or max.', ERROR_MISSING_MIN_MAX);
if ($minMax[0] === '' || $minMax[1] === '') {
$this->store->setVar(SYSTEM_FORM_ELEMENT_MESSAGE, 'Missing definition of value for min or max.', STORE_SYSTEM);
throw new UserException('Missing definition of value for min or max.', ERROR_MISSING_MIN_MAX);
}
$errorText = "Value '$value' is smaller than min '$minMax[0]' or bigger than max '$minMax[1]'.";
// Date/Time: convert in object to make a comparison.
......@@ -160,6 +165,7 @@ class Save {
if ($minMax[0] <= $valueCompare && $valueCompare <= $minMax[1])
return $value;
$this->store->setVar(SYSTEM_FORM_ELEMENT_MESSAGE, $errorText, STORE_SYSTEM);
throw new UserException($errorText, ERROR_MIN_MAX_VIOLATION);
break;
......@@ -169,7 +175,8 @@ class Save {
case 'number':
case 'email':
$htmlPatternAttribute = $this->inputCheckPattern[$formElement['checkType']];
$arr = OnArray::inputCheckPatternArray();
$htmlPatternAttribute = $arr[$formElement['checkType']];
// remove 'pattern="' and closing ".
$pattern = substr($htmlPatternAttribute, 9, strlen($htmlPatternAttribute) - 9 - 1);
break;
......@@ -184,7 +191,9 @@ class Save {
if (preg_match($pattern, $value) === 1)
return $value;
throw new UserException("Value $value violates checkrule " . $formElement['checkType'] . " with pattern '$pattern'.", ERROR_PATTERN_VIOLATION);
$errorText = "Value $value violates checkrule " . $formElement['checkType'] . " with pattern '$pattern'.";
$this->store->setVar(SYSTEM_FORM_ELEMENT_MESSAGE, $errorText, STORE_SYSTEM);
throw new UserException($errorText, ERROR_PATTERN_VIOLATION);
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment