The form field that is supposed to be empty was filled. In case you are not a spam-bot, please try again leaving the field blank

Hello guys, i’m using kirby-uniform and uniform-recaptcha plugins so i’ve created my form but when I’m trying to send a message it shows the follow message:

The form field that is supposed to be empty was filled. In case you are not a spam-bot, please try again leaving the field blank.

I completed all the required fields and the form shows the same message no matter what.

Here’s my code, what you think it is wrong?:

Controller

<?php

use Uniform\Form;

return function ($kirby)
{
    $form = new Form([
        'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Please enter a valid email address',
        ],
        'name' => [],
        'message' => [
            'rules' => ['required'],
            'message' => 'Please enter a message',
        ],
        'recipient' => [
            'rules' => ['required'],
            'message' => 'Please choose a recipient',
        ],
        'gdprconsent' => [
                'rules' => ['required'],
                'message' => "Your consent is required.",
        ],
    ]);

    if ($kirby->request()->is('POST')) {
        $form->emailSelectAction([
            'from' => 'contactpz@pe-zona.ro',
            'allowed-recipients' => [
                'vanzari'     => 'vanzari@pe-zona.ro',
                'reclamatii'  => 'reclamatii@pe-zona.ro',
                'recrutari' => 'admin@pe-zona.ro'
            ],
        ]);
    }


    return compact('form');
};
return function ($page, $kirby, $site) {

  // Meta
  $seo = $kirby->controller('seo' , compact('page', 'site', 'kirby'));

  // Override Meta Title
  $metatitle = $site->title().' | '.$page->seotitle();

  $data = compact('metatitle');

  return a::merge($seo, $data);

};
?>

Form:

<section class="containercontact">

<div class="containertextinteractiv">
  <div class="textinteractiv">
    <p>Ai o întrebare?</p>
    <h1>Contactează-ne</h1>
    <p>Suntem aici pentru a vă ajuta și răspunde la orice întrebări pe care le-ați putea avea. 🙂</p>
  </div>
</div>

<form id="formular" action="<?php echo $page->url() ?>" method="POST">
  <label>Numele tău:</label>
  <input class="campnm" <?php if ($form->error('name')): ?> class="error"<?php endif; ?> name="name" type="text" value="<?php echo $form->old('name') ?>">

  <label>Adresă email:</label>
  <input class="campnm" <?php if ($form->error('email')): ?> class="error"<?php endif; ?> name="email" type="email" value="<?php echo $form->old('email') ?>">


    <label>Mesaj:</label>
    <textarea<?php if ($form->error('message')): ?> class="error"<?php endif; ?> name="message"><?php echo $form->old('message') ?></textarea>
    <div>Selectează departament</div>
    <select name="recipient">
        <?php $value = $form->old('recipient') ?>
        <option value="vanzari"<?php e($value=='vanzari', ' selected')?>>Vânzări</option>
        <option value="reclamatii"<?php e($value=='reclamatii', ' selected')?>>Reclamații</option>
        <option value="recrutari"<?php e($value=='recrutari', ' selected')?>>Recrutări</option>
    </select>
    <?php echo csrf_field() ?>
    <?php echo recaptchaField() ?>
    <label class="termeni">
    <?php $value = $form->old('gdprconsent') ?>
    <input type="checkbox" name="gdprconsent" value="gdprconsent"<?php e(!$value || $value=='gdprconsent', ' unchecked')?>/> <a href="#">Accept termenii acestui site</a>
    </label>
    <input class="butontrimite" type="submit" value="Submit">

</form>
<?= recaptchaScript() ?>
<?php if ($form->success()): ?>
    Mulțumim pentru mesaj! Veți fi contactat în cel mai scurt timp posibil.
<?php else: ?>
    <?php snippet('uniform/errors', ['form' => $form]) ?>
<?php endif; ?>

</section> <!-- CONTAINER CONTACT -->

You are not calling $form->recaptchaGuard() in your controller: GitHub - eXpl0it3r/kirby-uniform-recaptcha: Kirby 3 Plugin Extension for the Uniform Plugin

On a side note, the second return function in your controller will not have any effect, so you can either remove it or incorporate the code within the first return function.

1 Like

Thanks, I added recaptchaGuard function now, but now I have a new error.

The ‘to’ option is required.

    return array_key_exists($key, $this->options) ? $this->options[$key] : $default;
}

/**
 * Get an option from the options array and throw an exception if it isn't set
 * @param string $key Option key
 * @return mixed
 * @throws Exception
 */
protected function requireOption($key)
{
    $value = $this->option($key);
    if ($value === null) {
        throw new Exception("The '{$key}' option is required.");
    }

    return $value;
}

So I try to add before the allowed-recipients the following ‘to’ => [allowed-recipients [options ] ] but it’s not working. I used the code from the docs but i’m to dumb

<?php

use Uniform\Form;

return function ($kirby)
{
    $form = new Form([
        'email' => [
            'rules' => ['required', 'email'],
            'message' => 'Please enter a valid email address',
        ],
        'name' => [],
        'message' => [
            'rules' => ['required'],
            'message' => 'Please enter a message',
        ],
        'recipient' => [
            'rules' => ['required'],
            'message' => 'Please choose a recipient',
        ],
        'gdprconsent' => [
                'rules' => ['required'],
                'message' => "Your consent is required.",
        ],
    ]);

    if ($kirby->request()->is('POST'))
    {
        $form->recaptchaGuard()
             ->emailAction(/* ... */);
    }

    if ($kirby->request()->is('POST')) {
    $form->emailAction([
        'to' => 'pz@pe-zona.ro',
        'from' => 'info@example.com',
    ]);
}

    if ($kirby->request()->is('POST')) {
        $form->emailSelectAction([
            'from' => 'contact@pe-zona.ro',
            'to' => [
            'allowed-recipients' => [
                'vanzari'     => 'vanzari@pe-zona.ro',
                'reclamatii'  => 'reclamatii@pe-zona.ro',
                'recrutari' => 'admin@pe-zona.ro'
            ],
          ],
        ]);
    }

    return compact('form');
};


return function ($page, $kirby, $site) {

  // Meta
  $seo = $kirby->controller('seo' , compact('page', 'site', 'kirby'));

  // Override Meta Title
  $metatitle = $site->title().' | '.$page->seotitle();

  $data = compact('metatitle');

  return a::merge($seo, $data);

};

This setup is not correct, see the docs for the emailSelectAction(), it doesn’t accept a to option.

I think it would make more sense if you put all your actions inside one if ($kirby->request()->is(‘POST’)) statement, why are there so many?

1 Like

I put them together now, but i still get the error: The ‘to’ option is required.

    if ($kirby->request()->is('POST')) {
        $form->emailSelectAction([
            'from' => 'contact@pe-zona.ro',
            'allowed-recipients' => [
                'vanzari'     => 'vanzari@pe-zona.ro',
                'reclamatii'  => 'reclamatii@pe-zona.ro',
                'recrutari' => 'admin@pe-zona.ro'
          ],
          $form->recaptchaGuard()
               ->emailAction(/* ... */)
        ]);
    }

Where is the error thrown, you have provided the code snippet, but without any context information.

if ($kirby->request()->is('POST')) {
    $form->recaptchaGuard()->emailSelectAction([
        'from' => 'contactpz@pe-zona.ro',
        'allowed-recipients' => [
            'vanzari'     => 'vanzari@pe-zona.ro',
            'reclamatii'  => 'reclamatii@pe-zona.ro',
            'recrutari' => 'admin@pe-zona.ro'
        ],
    ]);
}

Now it’s all gucci< kiss