CodeIgniter Forums
Repopulating radio buttons - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Repopulating radio buttons (/thread-54612.html)

Repopulating radio buttons - El Forum - 09-17-2012

Hi guys,

after some research over here, I haven't found a solution yet for this issue.

I'm using the form helper and the form validation class. Validation and repopulating data works fine except with radio buttons.

Here's the code:

echo form_radio('fieldname', 'value1', set_radio('fieldname', 'value1', TRUE);
echo form_radio('fieldname', 'value2', set_radio('fieldname', 'value2');

I've read several threads mixing the classic html radio codes with set_radio, but i'd like to keep using the form helper. Even tried to set a validation rule for this buttons but this has no effect either.

I'm also var_dumping $post and it never shows any selection of radio buttons but the text inputs appear perfectly. Any ideas?


Repopulating radio buttons - El Forum - 09-17-2012

I've solved it with a little workaround, skipping set_radio():

if($this->input->post('fieldname') == 'value1')
    $default_1 = TRUE;
    $default_2 = FALSE;
    $default_1 = FALSE;
    $default_2 = TRUE;

echo form_radio('fieldname', 'value1', $default_1);
echo form_radio('fieldname', 'value2', $default_2);

Hope it helps.

Repopulating radio buttons - El Forum - 09-17-2012

You want to use set_value() anyway. set_radio() is for when you aren't using the form_helper to create the radio. It's for when you manually create the radio element, as mentioned in the user guide.

Repopulating radio buttons - El Forum - 09-18-2012

Sorry, I missed it. Maybe you're refering to this?

Note: If you use any of the form helper functions listed in this page the form values will be prepped automatically, so there is no need to call this function. Use it only if you are creating your own form elements.

I was looking for that info in the Form Validation Class and not the Form Helper.

Anyway thanks CroNiX!