Skip to content
Snippets Groups Projects
Commit 6891b079 authored by Jared Hancock's avatar Jared Hancock
Browse files

forms: oops: Properly validate forms for agents

This patch fixes a small glitch where validation might be bypassed for
fields for agents. Previously there was a glitch where required fields would
have their validation errors ignored.
parent 24004ee2
Branches
Tags
No related merge requests found
......@@ -129,7 +129,7 @@ class UsersAjaxAPI extends AjaxController {
Http::response(404, 'Unknown user');
$errors = array();
if($user->updateInfo($_POST, $errors))
if ($user->updateInfo($_POST, $errors, true) && !$errors)
Http::response(201, $user->to_json());
$forms = $user->getForms();
......
......@@ -732,23 +732,24 @@ class DynamicFormEntry extends VerySimpleModel {
if (!is_array($this->_errors)) {
$this->_errors = array();
$this->getClean();
foreach ($this->getFields() as $field)
foreach ($this->getFields() as $field) {
if ($field->errors() && (!$filter || $filter($field)))
$this->_errors[$field->get('id')] = $field->errors();
}
}
return !$this->_errors;
}
function isValidForClient() {
$filter = function($f) {
return !$f->isRequiredForUsers();
return $f->isVisibleToUsers();
};
return $this->isValid($filter);
}
function isValidForStaff() {
$filter = function($f) {
return !$f->isRequiredForStaff();
return $f->isVisibleToStaff();
};
return $this->isValid($filter);
}
......
......@@ -678,6 +678,9 @@ class TextboxField extends FormField {
&& false !== @preg_match($wrapped, ' ')) {
return $wrapped;
}
if ($value == '//iu')
return '';
return $value;
},
'validators' => function($self, $v) {
......
......@@ -493,13 +493,15 @@ class User extends UserModel {
return User::importCsv($stream, $extra);
}
function updateInfo($vars, &$errors) {
function updateInfo($vars, &$errors, $staff=false) {
$valid = true;
$forms = $this->getDynamicData();
foreach ($forms as $cd) {
$cd->setSource($vars);
if (!$cd->isValidForClient())
if ($staff && !$cd->isValidForStaff())
$valid = false;
elseif (!$cd->isValidForClient())
$valid = false;
elseif ($cd->get('type') == 'U'
&& ($form= $cd->getForm())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment