kirby-uniform
kirby-uniform copied to clipboard
Calc guard error message displays in wrong translation
Describe the bug I discovered if I fill wrong result in calc guard field, calc guard shows error message in English, even though my site is in Czech. This is the relevant part of the controller:
$form = new Form([
// other rules ...
"captcha" => [
"rules" => ["required", "num"],
"message" => "Vyplňte pole"
],
]);
This is the template:
<label>
Vypňte výsledek příkladu <?= uniform_captcha() ?> =
<?= captcha_field("", "contact-form__field"); ?>
</label>
<?php if(array_key_exists("captcha", $form->errors())): ?>
<p class="contact-form__error"><?= $form->errors()["captcha"][0] ?></p>
<?php endif; ?>
Now, when I leave the captcha field blank, the returned error message is as defined in new Form().
But when I fill wrong result (let's say 3 + 3 = 77), English error message 'Please solve the arithmetic problem.' is returned.
Expected behavior Czech error message should be shown.
Additional context I tried it in Kirby 4.6.1 plainkit with the latest Uniform.
I found what causes this issue. It actually is Kirby itself. My site is single-language and the language is not English, which is default in Kirby. Turns out Kirby does not handle locale settings well on single-language pages. There is even a suggestion addressing this behavior on kirby.nolt.io
Were you able to solve this issue?
Unfortunately not really. As I needed some quick fix, instead of writing this:
<?php if(array_key_exists("captcha", $form->errors())): ?>
<p class="contact-form__error"><?= $form->errors()["captcha"][0] ?></p>
<?php endif; ?>
I wrote this:
<?php if($form->error("captcha")): ?>
<p class="contact-form__error">My custom error message ...</p>
<?php endif; ?>
So basically bypassing captcha field error message translation. Not a solution, just a workaround...
Thanks for the update! So if this is a Kirby issue I don't think we can do anything else about this here.