[TASK] Improve validation handling
This commit is contained in:
parent
1cd9c2567e
commit
f40c4b6e74
@ -90,6 +90,11 @@ class ActionController extends BaseController
|
|||||||
*/
|
*/
|
||||||
protected $redirect = null;
|
protected $redirect = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is valid
|
||||||
|
*/
|
||||||
|
protected $isValid = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* errors
|
* errors
|
||||||
*/
|
*/
|
||||||
@ -366,6 +371,15 @@ class ActionController extends BaseController
|
|||||||
{
|
{
|
||||||
$validator = new Validator();
|
$validator = new Validator();
|
||||||
$input = $this->arrayRemoveEmptyStrings($input);
|
$input = $this->arrayRemoveEmptyStrings($input);
|
||||||
|
//@todo make optional when usiing rest api
|
||||||
|
//array_walk_recursive(
|
||||||
|
// $input,
|
||||||
|
// function (&$value) {
|
||||||
|
// if (filter_var($value, FILTER_VALIDATE_INT)) {
|
||||||
|
// $value = (int)$value;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//);
|
||||||
$input = $this->arrayToObject($input);
|
$input = $this->arrayToObject($input);
|
||||||
$validationResult = $validator->dataValidation(
|
$validationResult = $validator->dataValidation(
|
||||||
$input,
|
$input,
|
||||||
@ -373,6 +387,7 @@ class ActionController extends BaseController
|
|||||||
-1
|
-1
|
||||||
);
|
);
|
||||||
if (!$validationResult->isValid()) {
|
if (!$validationResult->isValid()) {
|
||||||
|
$this->isValid = false;
|
||||||
$this->responseStatus = [400 => 'validationError'];
|
$this->responseStatus = [400 => 'validationError'];
|
||||||
foreach ($validationResult->getErrors() as $error){
|
foreach ($validationResult->getErrors() as $error){
|
||||||
$errorLabel = null;
|
$errorLabel = null;
|
||||||
@ -607,6 +622,7 @@ class ActionController extends BaseController
|
|||||||
return json_encode($result);
|
return json_encode($result);
|
||||||
}
|
}
|
||||||
$result = array_merge($result, ['cid' => $this->contentObjectUid]);
|
$result = array_merge($result, ['cid' => $this->contentObjectUid]);
|
||||||
|
$result = array_merge($result, ['isValid' => $this->isValid]);
|
||||||
if (!empty($this->ajaxEnv)) {
|
if (!empty($this->ajaxEnv)) {
|
||||||
$result = array_merge(
|
$result = array_merge(
|
||||||
$result,
|
$result,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user