We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Mutiple render checkbox in volt

Hi all

I have a table Category contain field , id, name, description with value

id name description
1 Backend this is backend
2 Frontend this is frontend
3 Other this is orther

and FormPost look like

    class PostForm extends Form
    {
       foreach (Category::find() as $key => $value) {
            $this->add(new Check('idCat[]', array('value' => $value->id)));
        }
        [..]
    }

Then in view I user render form but it get last value

<input type="checkbox" class="form-control input-sm" value="3" name="idCat[]">

My question, how to get result look like

<input type="checkbox" class="form-control input-sm" value="1" name="idCat[]">
<input type="checkbox" class="form-control input-sm" value="2" name="idCat[]">
<input type="checkbox" class="form-control input-sm" value="3" name="idCat[]">


58.4k
edited Nov '14

If in form i create function

   public function renderCat()
    {
        foreach (Category::find() as $key => $value) {
            echo "<label for='category-{$key}'>";
            echo "<input type='checkbox' value='$value->id' name='categories[]'> $value->name";
            echo "</label>";
        }
    }

Then in volt I call

{{form.rendercat()}}

It working but it pefect yet ?