Uniform: Sending multiple checkbox options

Hi there!

I’m aware that a solution for my uniform checkbox problem already exists, but I’m not quite sure how to use it (I’m kind of a half-knowledge user):

I’m using the uniform plugin for my website and I want to integrate a multiple checkbox section…

Right now the snippet part looks like this (taken from here)

<label>Extra 1
    <input type="checkbox"<?php e($form->hasError('qty'), ' class="erroneous"')?>  name="qty[]" value="<?php echo @$form->value('qty')[0] ?>" />
</label>
<label>Extra 2
    <input type="checkbox"<?php e($form->hasError('qty'), ' class="erroneous"')?>  name="qty[]" value="<?php echo @$form->value('qty')[1] ?>" />
</label>
<label>Extra 3
    <input type="checkbox"<?php e($form->hasError('qty'), ' class="erroneous"')?>  name="qty[]" value="<?php echo @$form->value('qty')[2] ?>" />
</label>

And the part in my email snippet like this:

Extras: <?php echo $form['qty']
Anrede: <?php echo $form['anrede']
Titel: <?php echo $form['titel']
Vorname: <?php echo $form['vorname']
...

I would love to get some practical input to solve this!!!

Nelli

Something like this should work:

Extras: <?php echo implode(', ', $form['qty']) ?>
Anrede: <?php echo $form['anrede'] ?>
Titel: <?php echo $form['titel'] ?>
Vorname: <?php echo $form['vorname'] ?>

implode is a built-in PHP function that joins array values into a string. In this case all selected/checked values are joined with commas.

Please note that you need to close your PHP tags in the email snippet. I have done it for the lines you posted, make sure to do the same for the other ones.

1 Like