Formit emailTpl with checkbox should display in a list

Hello,

i have a Formit Form which contain checkboxes.

All is working ok but in my emailTpl when i output the checkbox as for example [[+checkbox]] it will display as a simple row of values.

How can i display the checked value in a beautiful list ?

So you have a checkbox group like this

<input type="checkbox" name="checkbox[]" value="option 1"> option 1<br>
<input type="checkbox" name="checkbox[]" value="option 2"> option 2<br>
<input type="checkbox" name="checkbox[]" value="option 3"> option 3

in your form and you want to output the selected options in your E-Mail template as a HTML list?

<ul><li>option 1</li><li>option 2</li></ul>

I guess for this, you’ll have to write a custom output modifier (or normal custom snippet) that separates the value of [[+checkbox]] at the \n characters and then adds the HTML tags.

Yes ok thanx for the directions.
i made a snippet and it works

/* checkboxToList */
/* [+checkbox:checkboxToList +] */

if (empty($input)) return '';

if (is_array($input)) {
    $mots = $input;
} else {
    $input = str_replace(["\r\n", "\r", "\n"], ',', $input);
    $mots = explode(',', $input);
}

$output = '<ul>';
foreach ($mots as $mot) {
    if (!empty(trim($mot))) {
        $output .= '<li>' . htmlspecialchars(trim($mot)) . '</li>';
    }
}
$output .= '</ul>';

return $output;

:grinning:

1 Like

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.