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

How could we read the checkbox values from .volt to .controller

Hi. In Phalcon I am using .volt for view purpose. In that I have the multiple checkboxes. How could I read the checkbox vlues from .volt to .controller fie?



85.5k

with ajax request ?

your question is a bit odd.

the controller displays the view and thats it, there is link between a view and controlller in that direction ?

Actually from View I am getting values to the Controller (By $this-request-getPost('')) but when I am trying to get the multiple checkbox values from a form I am unable to get all the values from view controller( and Here I would to know that how could we check whether checkbox is checked (or) not in controller).

Hope this give more clarity of my question. Thank you



85.5k

you are right, there is a link in that direction, i am dumb.

but i still dont understand the idea what you are trying to do.

user enters a url -> controller ( we pick a view here, we do some queries maybe ? ) -> we display the view

so user didnt have an option to click any checkboxes yet ?

for more clarity below is the code I used in form

{{ check_field( 'name':'myClass', 'data-size':'big', 'id':'id'~studentInfo.id, 'value':studentInfo.id) }}

the above one is in loop. Now how could I get the all the checkbox details in controller. In controller I am using $_REQUEST('myClass') I am getting only once check box info but not all the checkboxes info. I need to get all checkboxes info.

Thank you

If your checkbox name in same name, you can try like this

In View Volt :

{% for category in categories %}

<input type="checkbox" value="{{ category.id }}" name="category[]">

{% endfor %}

In Controller :

$cats=$this->request->getPost('category');

foreach ($cats as $cat){

echo $cat;

}

Thank you Izo and Aditya Y Pradhana . Yes you guyss are right for name paramter I need to give the '[]'. '{{ check_field( 'name':'myClass[]', 'data-size':'big', 'id':'id'~studentInfo.id, 'value':studentInfo.id) }}'

Now I am getting the values as array. Thanks for your help friends :)