Skip to content

Commit 6658519

Browse files
committed
fix(checkboxesfield,radiosfield,selectfield): add missing error messages
1 parent acbcd09 commit 6658519

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

inc/field/checkboxesfield.class.php

+10
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,19 @@ public function isValidValue($value): bool {
204204

205205
foreach ($value as $item) {
206206
if (trim($item) == '') {
207+
Session::addMessageAfterRedirect(
208+
sprintf(__('Empty values are not allowed: %s', 'formcreator'), $this->getTtranslatedLabel()),
209+
false,
210+
ERROR
211+
);
207212
return false;
208213
}
209214
if (!in_array($item, $this->getAvailableValues())) {
215+
Session::addMessageAfterRedirect(
216+
sprintf(__('This value %1$s is not alowed: %2$s', 'formcreator'), $item, $this->getTtranslatedLabel()),
217+
false,
218+
ERROR
219+
);
210220
return false;
211221
}
212222
}

inc/field/radiosfield.class.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,18 @@ public function isValidValue($value): bool {
204204
if ($value == '') {
205205
return true;
206206
}
207+
207208
$value = trim($value);
208-
return in_array($value, $this->getAvailableValues());
209+
if (!in_array($value, $this->getAvailableValues())) {
210+
Session::addMessageAfterRedirect(
211+
sprintf(__('This value %1$s is not allowed: %2$s', 'formcreator'), $value, $this->getTtranslatedLabel()),
212+
false,
213+
ERROR
214+
);
215+
return false;
216+
}
217+
218+
return true;
209219
}
210220

211221
public static function canRequire(): bool {

inc/field/selectfield.class.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,16 @@ public function isValidValue($value): bool {
118118
return true;
119119
}
120120
$value = trim($value);
121-
return in_array($value, $this->getAvailableValues());
121+
if (!in_array($value, $this->getAvailableValues())) {
122+
Session::addMessageAfterRedirect(
123+
sprintf(__('This value %1$s is not allowed: %2$s', 'formcreator'), $value, $this->getTtranslatedLabel()),
124+
false,
125+
ERROR
126+
);
127+
return false;
128+
}
129+
130+
return true;
122131
}
123132

124133
public function equals($value): bool {

0 commit comments

Comments
 (0)