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

select "multiple"

I have an html <form> which filters a paginator (so users can filter on what rows they view). I just got a request from the users that they want to be able to select more than one value. Changing all the selects to checkboxes is a big pain, but there is this:

https://www.w3schools.com/tags/att_select_multiple.asp

In my volt I did:

{{form.render('original_md',['multiple':'multiple'])}}

And it works in the browser, but when I submit the form, only once value is passed. Does phalcon support the select multiuple functionality?

edited Feb '16

Hey, read this: https://forum.phalcon.io/discussion/2646/phalcon-tag-select-multiple-assign-defaults-from-controller and tell us if you have any questions.

Notice the [] in element name :)



40.7k
edited Feb '16

Well as it turns out I am implementing it with checkboxes since I find that a little more elegant. But I am still having problems. From the form:

$doctors = Doctor::find();

foreach($doctors as $id=>$doctor){
     $this->add(new Check('original_md['.$doctor->getId().']',array($doctor->getFirstName().' '.$doctor->getLastName()=>$doctor->getId())));
}

from the controller:

$doctors = Doctor::find(array("conditions"=>"is_deleted=0","order"=>"last_name"));
$this->view->doctors = $doctors;

So that the list of doctors is available in the volt, then later down in the controller:

$md_str = implode(",",array_keys($this->request->getPost("original_md","string")));
$results = $status->getPatientsWithStudyStatus(array("conditions"=>"original_md in (:md:)",bind=>array('md'=>$md_str)));

then the volt:

{% for doctor in doctors %}
    {% set id = "original_md[" ~ doctor.getId() ~ "]" %}
    {{form.render(id)}} {{doctor.getValue("first_name")}} {{doctor.getValue("last_name")}}<BR>
{% endfor %}

if I check one of the original_md boxes in the volt then it works. If I check more than one of the checkboxes, it only takes the first one one even with the "in" clause. Is that a bug? If I have to I will go back to <select> but that thread you linked was not at all clear how the last post was a solution :(