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

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to properly use radio_field set ?

I'm attempting to populate a radio field's value from the controller but it doesn't seem to work as expected.

In my controller action:

$search_in = $this->request->get('search_in','string','all');
\Phalcon\Tag::setDefault("search_in", $search_in);

In my volt view I have:

{{ radio_field('search_in_label', 'name':'search_in', 'value':'label') }}
{{ radio_field('search_in_address', 'name':'search_in', 'value':'address') }}
{{ radio_field('search_in_all', 'name':'search_in', 'value':'all') }}

I have to set the id, name and value separately to produce the HTML needed to 'link' the radio fields. Unfortunately this seems to cause the template rendering to get confused; it seems the rendering of a 'checked' value is based on the 'id', rather than the 'name' of the form field.

The documentation does not provide any examples for radio_field() so I'm not quite sure if I'm using it correctly.

I'm using Phalcon v1.2.5.

Any thoughts?



5.5k
Accepted
answer

Figured it out. This works.


{{ radio_field('search_in', 'value':'label','id':'search_in_label') }}
{{ radio_field('search_in', 'value':'address','id':'search_in_address') }}
{{ radio_field('search_in', 'value':'all','id':'search_in_all') }}

Basically you override the id attribute instead of the name attribute, and set the value attribute explicitly (otherwise it's always set to the value of $search_in, and all elements are marked as 'checked').