Skip to content

Commit d630302

Browse files
committed
fix(formanswer): prevent silent rejection of answers
1 parent 6658519 commit d630302

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

inc/formanswer.class.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -1397,12 +1397,32 @@ protected function validateFormAnswer($input): bool {
13971397
$this->isAnswersValid = !in_array(false, $fieldValidities, true);
13981398

13991399
if ($this->isAnswersValid) {
1400+
$form = $this->getForm();
1401+
$domain = PluginFormcreatorForm::getTranslationDomain($form->getID());
14001402
foreach ($this->questionFields as $id => $field) {
14011403
if (!$this->questionFields[$id]->isPrerequisites()) {
14021404
continue;
14031405
}
1406+
// Count the errors in session
1407+
$errors_count = $_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR]
1408+
? count($_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR])
1409+
: 0;
14041410
if (PluginFormcreatorFields::isVisible($field->getQuestion(), $this->questionFields) && !$this->questionFields[$id]->isValid()) {
1405-
$this->isAnswersValid = false;
1411+
$new_errors_count = $_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR]
1412+
? count($_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR])
1413+
: 0;
1414+
1415+
if ($new_errors_count <= $errors_count) {
1416+
// If there are new errors, we add a message to the user
1417+
$field_name = __($field->getQuestion()->fields['name'], $domain);
1418+
Session::addMessageAfterRedirect(
1419+
sprintf(__('Answer is invalid in %1$s', 'formcreator'), $field_name),
1420+
true,
1421+
ERROR
1422+
);
1423+
}
1424+
1425+
$this->isAnswersValid = false;
14061426
}
14071427
}
14081428
}

0 commit comments

Comments
 (0)