Kirby Uniform Plugin: Multiple Checkbox

Hey there,

I am trying to setup a checkbox with the uniform plugin, that sends multiple values, when they are checked. Unfortunately I cannot get it work. Is this even possible?

Thanks
Matthias

Check out this: Uniform plugin – Keep checkboxes status on error

@texnixe

Thanks for your reply. It is still not sending.

I registered the fields like this:

  $form = new Form([
// Fields
'type' => [],

]);

And then in the template:

      <ul class="contactForm__type">
        <?php $value = $form->old('type') ?>
        <li>
          <input type="checkbox" id="buero" name="type[]" value="Büroreinigung"<?php e($form->value('Büroreinigung'), ' checked')?>/>
          <label for="buero">Büroreinigung</label>
        </li>
        <li>
          <input type="checkbox" id="glass" name="type[]" value="Glasreinigung"<?php e($form->value('Glasreinigung'), ' checked')?>/>
          <label for="glass">Glasreinigung</label>
        </li>
      </ul>

The email template looks currently like this:
<?php

if (array_key_exists('type', $form)) {
    foreach ($form['type'] as $key => $value) {
    echo $value . "\n";
}
} else {
    echo 'Nichts ausgewählt!' . "\n" . "\n";
}

It is simply reloading the form page, instead of sending the mailform and forwarding to the thanks-page. Any ideas?

Hm, I only tested a quick example without Uniform, so I have to install that first. I’ll try to look into this later.

Thank you!

Could you quickly post your complete controller and form for testing?

We are talking Kirby 3, right?

I did a quick test and in my example, the data is sent.

For the form to show the checked values, I had to make the following changes:

<?php $value = $form->old('type') !== '' ? $form->old('type') : [] ?>
<ul class="contactForm__type">

        <li>
          <input type="checkbox" id="buero" name="type[]" value="Büroreinigung" <?= in_array('Büroreinigung', $value)? 'checked':'' ?>/>
          <label for="buero">Büroreinigung</label>
        </li>
        <li>
          <input type="checkbox" id="glass" name="type[]" value="Glasreinigung" <?= in_array('Glasreinigung', $value)? 'checked':'' ?>/>
          <label for="glass">Glasreinigung</label>
        </li>
</ul>

Looks a bit ugly but seems to work.

1 Like

@texnixe
Awesome - it works! Thanks a lot for looking into it and the great support.

Best
Matthias