• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
form_radio() validation problem

#1
[eluser]Unknown[/eluser]
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:
Code:
$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:
Code:
$this->form_validation->set_rules('radio_select', 'Radio button', 'required');


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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