Skip to content

Commit

Permalink
fix(formanswer): handle answers when valdiating
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Apr 1, 2021
1 parent 2cb3f4e commit a5a6a6c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,29 @@ public function prepareInputForUpdate($input) {
switch (PluginFormcreatorFormAnswerValidation::computeValidationStatus($this)) {
case PluginFormcreatorForm_Validator::VALIDATION_STATUS_ACCEPTED:
$input['status'] = self::STATUS_ACCEPTED;

// check if the input contains answers to validate
$hasAnswers = false;
foreach (array_keys($input) as $key) {
if (strpos($key, 'formcreator_field_') === 0) {
$hasAnswers = true;
break;
}
}
$skipValidation = !$hasAnswers;

break;
case PluginFormcreatorForm_Validator::VALIDATION_STATUS_REFUSED:
$input['status'] = self::STATUS_REFUSED;

// Update is restricted to a subset of fields
$input = [
'id' => $input['id'],
'status' => $input['status'],
'comment' => isset($input['comment']) ? $input['comment'] : 'NULL',
];
$skipValidation = true;

break;
default:
$input['status'] = self::STATUS_WAITING;
Expand Down

0 comments on commit a5a6a6c

Please sign in to comment.