Welcome Guest, Not a member yet? Register   Sign In
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');


Messages In This Thread
form_radio() validation problem - by El Forum - 10-04-2011, 12:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB