Skip to content

Commit

Permalink
Improve warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
budziam committed Sep 20, 2023
1 parent 1aa9238 commit 8f06b91
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions includes/Http/Validation/Rules/PostalCodeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class PostalCodeRule extends RegexRule
{
protected string $errorMessage = "field_postal_code_warn";

public function __construct(string $pattern = "/^\d{2}-\d{3}$/")
{
parent::__construct($pattern);
Expand Down
5 changes: 3 additions & 2 deletions includes/Http/Validation/Rules/RegexRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

class RegexRule extends BaseRule
{
private string $pattern;
protected string $pattern;
protected string $errorMessage = "field_regex_warn";

public function __construct(string $pattern)
{
Expand All @@ -17,7 +18,7 @@ public function __construct(string $pattern)
public function validate($attribute, $value, array $data): void
{
if (!preg_match($this->pattern, $value)) {
throw new ValidationException($this->lang->t("field_regex_warn"));
throw new ValidationException($this->lang->t($this->errorMessage));
}
}
}
3 changes: 2 additions & 1 deletion translations/english/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"field_length_min_warn" => "Field must consist of min. {1} chars.",
"field_must_be_number" => "Field must contain a number.",
"field_no_empty" => "Field cannot be empty.",
"field_regex_warn" => "Field value does not meet requirements.",
"field_postal_code_warn" => "Value has to match 00-000 format.",
"field_regex_warn" => "Value does not meet requirements.",
"firstname" => "Firstname",
"forever" => "Forever",
"form_wrong_filled" => "Not all the form fields were filled correctly.",
Expand Down
1 change: 1 addition & 0 deletions translations/polish/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"field_length_min_warn" => "Pole musi się składać z co najmniej {1} znaków.",
"field_must_be_number" => "W polu musi się znajdować liczba.",
"field_no_empty" => "Pole nie może być puste.",
"field_postal_code_warn" => "Wprowadzona wartość musi być formatu 00-000.",
"field_regex_warn" => "Wprowadzona wartość nie spełnia wymagań.",
"firstname" => "Imię",
"forever" => "Na zawsze",
Expand Down

0 comments on commit 8f06b91

Please sign in to comment.