Skip to content

Commit

Permalink
Merge branch 'support/2.13.0' into support/2.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jan 8, 2024
2 parents dbc66cb + 09682e9 commit 3061bc1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
35 changes: 34 additions & 1 deletion inc/field/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,40 @@ public function isValid(): bool {
return false;
}

// All is OK
return $this->isValidValue($this->value);
}

public function isValidValue($value): bool {
if (strlen($value) == 0) {
return true;
}

$parameters = $this->getParameters();

$stripped = strip_tags($value);

// Check the field matches the format regex
$regex = $parameters['regex']->fields['regex'];
if ($regex !== null && strlen($regex) > 0) {
if (!preg_match($regex, $stripped)) {
Session::addMessageAfterRedirect(sprintf(__('Specific format does not match: %s', 'formcreator'), $this->question->fields['name']), false, ERROR);
return false;
}
}

// Check the field is in the range
$rangeMin = $parameters['range']->fields['range_min'];
$rangeMax = $parameters['range']->fields['range_max'];
if ($rangeMin > 0 && strlen($stripped) < $rangeMin) {
Session::addMessageAfterRedirect(sprintf(__('The text is too short (minimum %d characters): %s', 'formcreator'), $rangeMin, $this->question->fields['name']), false, ERROR);
return false;
}

if ($rangeMax > 0 && strlen($stripped) > $rangeMax) {
Session::addMessageAfterRedirect(sprintf(__('The text is too long (maximum %d characters): %s', 'formcreator'), $rangeMax, $this->question->fields['name']), false, ERROR);
return false;
}

return true;
}

Expand Down
9 changes: 6 additions & 3 deletions inc/target_actor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con
case self::ACTOR_TYPE_PERSON:
case self::ACTOR_TYPE_AUTHORS_SUPERVISOR:
$user = new User;
$users_id = plugin_formcreator_getFromDBByField($user, 'name', $input['actor_value']);
$field = $idKey == 'id' ? 'id' : 'name';
$users_id = plugin_formcreator_getFromDBByField($user, $field, $input['actor_value']);
if ($users_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a user: %1$s'), $input['actor_value']));
}
Expand All @@ -203,7 +204,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con

case self::ACTOR_TYPE_GROUP:
$group = new Group;
$groups_id = plugin_formcreator_getFromDBByField($group, 'completename', $input['actor_value']);
$field = $idKey == 'id' ? 'id' : 'completename';
$groups_id = plugin_formcreator_getFromDBByField($group, $field, $input['actor_value']);
if ($groups_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a group: %1$s'), $input['actor_value']));
}
Expand All @@ -212,7 +214,8 @@ public static function import(PluginFormcreatorLinker $linker, $input = [], $con

case self::ACTOR_TYPE_SUPPLIER:
$supplier = new Supplier;
$suppliers_id = plugin_formcreator_getFromDBByField($supplier, 'name', $input['actor_value']);
$field = $idKey == 'id' ? 'id' : 'name';
$suppliers_id = plugin_formcreator_getFromDBByField($supplier, $field, $input['actor_value']);
if ($suppliers_id === false) {
throw new ImportFailureException(sprintf(__('Failed to find a supplier: %1$s'), $input['actor_value']));
}
Expand Down
4 changes: 3 additions & 1 deletion inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,10 @@ protected function setTargetLocation($data, $formanswer) {
'plugin_formcreator_questions_id' => $this->fields['location_question']
]
])->current();
if (isset($location['answer']) && ctype_digit($location['answer'])) {
if (isset($location['answer']) && !Location::isNewID($location['answer'])) {
$location = $location['answer'];
} else {
$location = null;
}
break;
case self::LOCATION_RULE_SPECIFIC:
Expand Down
2 changes: 1 addition & 1 deletion js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ var plugin_formcreator = new function() {
.off('click');
$(form).removeAttr('data-submitted');

if (xhr.responseText == '') {
if (xhr.responseText.trim() == '') {
displayAjaxMessageAfterRedirect();
return;
}
Expand Down

0 comments on commit 3061bc1

Please sign in to comment.