• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repopulating radio buttons

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?


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.

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.

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!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.