Uniform, recaptcha guard, languages and no errors

Hi,

I’m in the process of using uniform, the reCaptcha guard in kirby 2 with multiple languages (German, English, French, Polish and Russian).

The issues are:

  • captcha gets only displayed in german
  • if the captcha has not been checked, there are no error messages

The languages are defined in config.php:

c::set('languages', array(
array(
	'code'    => 'de',
	'name'    => 'Deutsch',
	'locale'  => 'de_DE',
	'url'     => '/',
	'default' => true,
),
array(
	'code'    => 'en',
	'name'    => 'English',
	'locale'  => 'en_US',
	'url'     => '/en',
),
array(
	'code'    => 'ru',
	'name'    => 'Pусский',
	'locale'  => 'ru_RU',
	'url'     => '/ru',
),
array(
	'code'    => 'fr',
	'name'    => 'Française',
	'locale'  => 'fr_FR',
	'url'     => '/fr',
),
array(
	'code'    => 'pl',
	'name'    => 'Polski',
	'locale'  => 'pl_PL',
	'url'     => '/pl',
)
));

c::set('language.detect', true);

form:

<form action="<?php echo $page->url() ?>" method="POST">
  <br>
  <p><?= $page->kontaktdatenContact() ?>:</p><br>
  <input <?php if ($form->error('lastName')): ?> class="error"<?php endif; ?> name="firstName" type="text" class="formStyle" value="<?php echo $form->old('firstName') ?>" placeholder="<?= $page->vornameContact() ?>"><?php snippet('form/error', ['field' => 'firstName']) ?><br>
  <input<?php if ($form->error('lastName')): ?> class="error"<?php endif; ?> name="lastName" type="text" class="formStyle" value="<?php echo $form->old('lastName') ?>" placeholder="<?= $page->nachnameContact() ?>">
    <!-- Use a snippet for the error so we don't repeat the same code for each field -->
    <?php snippet('form/error', ['field' => 'lastName']) ?><br>

  <input name="department" type="text" class="formStyle" value="<?php echo $form->old('department') ?>" placeholder="<?= $page->abteilungContact() ?>"><br>

  <input<?php if ($form->error('company')): ?> class="error"<?php endif; ?> name="company" type="text" class="formStyle" value="<?php echo $form->old('company') ?>" placeholder="<?= $page->firmaContact() ?>">
    <?php snippet('form/error', ['field' => 'company']) ?><br>

  <input<?php if ($form->error('street')): ?> class="error"<?php endif; ?> name="street" type="text" class="formStyle" value="<?php echo $form->old('street') ?>" placeholder="<?= $page->strasseContact() ?>">
  <?php snippet('form/error', ['field' => 'street']) ?><br>

  <input<?php if ($form->error('city')): ?> class="error"<?php endif; ?> name="city" type="text" class="formStyle" value="<?php echo $form->old('city') ?>" placeholder="<?= $page->plzContact() ?>">
    <?php snippet('form/error', ['field' => 'city']) ?><br>

  <input name="phone" type="text" class="formStyle" value="<?php echo $form->old('phone') ?>" placeholder="<?= $page->telefonContact() ?>"><br>

  <input<?php if ($form->error('email')): ?> class="error"<?php endif; ?> name="email" type="email" class="formStyle" value="<?php echo $form->old('email') ?>" placeholder="<?= $page->mailContact() ?>">
    <?php snippet('form/error', ['field' => 'email']) ?><br>

  <p><?= $page->nachrichtContact() ?></p><br>
  <textarea<?php if ($form->error('message')): ?> class="error"<?php endif; ?> name="message" class="formStyleArea"><?php echo $form->old('message') ?></textarea>
    <?php snippet('form/error', ['field' => 'message']) ?>

  <input type="checkbox" name="cont_agree" value="Ich bin einverstanden"><label><?= $page->disclaimerContact()->kirbytext() ?></label>
    <?php snippet('form/error', ['field' => 'cont_agree']) ?>
  <br><br>
  <?php echo csrf_field() ?>
  <?php echo honeypot_field() ?>
  <p><strong><?= $page->captchaContact() ?></strong></p><br>
  <?php echo recaptcha_field() ?><br>
  <input type="submit" value="<?= $page->sendenContact() ?>" class="submitbtn"><br>
  <input type="reset" value="<?= $page->zurueckContact() ?>" class="resetbtn">
  <!-- Show errors of the email actions if there are any -->
  <?php snippet('form/error', ['field' => \Uniform\Actions\EmailAction::class]) ?>
</form>
<?php echo embed_recaptcha_js(); ?>

controller:

<?php

use Uniform\Form;

return function ($site, $pages, $page)
{
    $form = new Form([
        'firstName' => [
            'rules' => ['required'],
            'message' => $page->vornameError()->value(),
        ],
        'lastName' => [
            'rules' => ['required'],
            'message' => $page->nachnameError()->value(),
        ],
        'department' => [],
        'company' => [],
        'street' => [],
        'city' => [],
        'phone' => [],
        'email' => [
            'rules' => ['required', 'email'],
            'message' => $page->emailError()->value(),
        ],
        'message' => [],
        'cont_agree' => [
            'rules' => ['required'],
            'message' => $page->datenschutzError()->value(),
        ],
        
    ]);

    if (r::is('POST')) {
        $form->recaptchaGuard()
        ->emailAction([
                'to' => 'contactform@xxx.com',
                'from' => 'info@xxx.com',
                // Dynamically generate the subject with a template.
                'subject' => 'Neue Nachricht von der Kontaktseite',
                'snippet' => 'emails/success-contact-sb',
            ])
            ->logAction([
                'file' => kirby()->roots()->site().'/registrations-contact.log',
            ])
            ->emailAction([
                // Send the success email to the email address of the submitter.
                'to' => $form->data('email'),
                'from' => 'info@xxx.com',
                // Set replyTo manually, else it would be set to the value of 'email'.
                'replyTo' => 'info@xxx.com',
                'subject' => 'Vielen Dank für Ihre Nachricht!',
                // Use a snippet for the email body (see below).
                'snippet' => 'emails/success-contact',
            ]);
        if ($form->success()) {
            go(page('landing-success')->url());
        }
        
    }

    return compact('form');
};

I used the extended example of the uniform documentation as a basis.

As i wrote above: no matter which language I pick in the frontend, only the german version of the captcha gets displayed and I don’t get any error messages from the captcha (the other ones by uniform work as supposed to). If everything is filled out as intended, both mails get sent and the user gets redirected to the success page. If I “forget” to confirm the captcha, the page refreshes, the fields have the old information stored and nothing happens. No mail, no error message.

Did I miss something? (probably…)

I’d really appreciate the help.

Daniel