We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Checkboxes In Table

Hello. I have a loop that creates multiple check boxes with the same name.

foreach ($openTickets as $ticketId)
            $checkbox = new Check('id-'.$ticketId['TicketId'], array("name" => "tickets[]", "id" => 'id-'.$ticketId['TicketId'] , "value" => $ticketId['TicketId']));
                    new PresenceOf(array(
                        "message" => 'Please select a ticket'

and on the phtml side.

foreach ($openTickets as $ticket) {?>
                    <tr >
                            <?php echo $form->render('id-'.$ticket['TicketId'])?>
                        <td><?php echo $ticket['DateCreatedDifference']; ?></td>
                <?php }?>

I am trying to force at least one checkbox to be checked. How do I achieve this.

Post fixed. Please read the Markdown FAQ for properly formatting code.


I don't use Volt, so it may not be 100% correct, but something like...

    $checked = false;
    foreach($openTickets as $ticketId) {
        $checkbox = new Check(...);
        if (!$checked) {
            $checkbox['checked'] = true;
            $checked = true;