CodeIgniter Forums
form_radio() validation problem - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: form_radio() validation problem (/thread-45737.html)

form_radio() validation problem - El Forum - 10-04-2011

I want to achieve 2 things with the radio buttons:

1) I want to know how to do validation for radio buttons.

2) Upon validation error, how to auto-select the last selected radio button.

Below is the code I have. I know I haven't done it correctly. If someone could guide me to the right direction, that'll be great. Thanks

In my view:
$form_data['radio1'] = array(
  'name'     => 'radio_select',
  'id'      => 'radio1',
  'value'    => 'radio1',
  'style'    => 'margin-bottom:12px; margin-right:4px;',
  'checked'  => set_value('true', isset($radio_select['radio1']['checked'])?TRUE:FALSE)

$form_data['radio2'] = array(
  'name'     => 'radio_select',
  'id'      => 'radio2',
  'value'    => 'radio2',
  'style'    => 'margin-bottom:12px; margin-right:4px;',
  'checked'  => set_value('false', isset($radio_select['radio2']['checked'])?TRUE:FALSE)

echo form_radio($form_data['radio1']); echo "Radio 1";
echo form_radio($form_data['radio2']);  echo "Radio 2";

In my controller:
$this->form_validation->set_rules('radio_select', 'Radio button', 'required');