Welcome Guest, Not a member yet? Register   Sign In
set_radio problem
#4

[eluser]Zeff[/eluser]
Hi TheFuzzyOne,

Thanks for your replies! I tried what you suggested, but it doesn't work... But, your snips put me on the right track: I examined the form_validation library and found (I should have known...) that set_radio(a,b,bool) method does not return TRUE or FALSE, but a string 'checked="checked"':

Code:
// library: /system/libraries/form_validation.php
/**
  * Set Radio
  *
  * Enables radio buttons to be set to the value the user
  * selected in the event of an error
  *
  * @access public
  * @param string
  * @param string
  * @return string
  */
public function set_radio($field = '', $value = '', $default = FALSE)
{
  if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
  {
   if ($default === TRUE AND count($this->_field_data) === 0)
   {
    return ' checked="checked"';
   }
   return '';
  }

  $field = $this->_field_data[$field]['postdata'];

  if (is_array($field))
  {
   if ( ! in_array($value, $field))
   {
    return '';
   }
  }
  else
  {
   if (($field == '' OR $value == '') OR ($field != $value))
   {
    return '';
   }
  }

  return ' checked="checked"';
}

Since the set_radio() method compares to POSTED data to do what it's written for, the $result variable can not be used to set. So the 'default value' (third) parameter in form_radio is the one to be set (see your last reply). I solved it this way:

Code:
echo '<p>';
    $attrs = array('name' => 'result', 'id' => 'id_resultval_11', 'class' => 'inputRadio');
    echo form_radio($attrs, '11', ($result==11)?TRUE:FALSE);
    echo form_label('Result 11', 'id_resultval_11');
echo '</p>';
echo '<p>';
    $attrs = array('name' => 'result', 'id' => 'id_resultval_1', 'class' => 'inputRadio');
    echo form_radio($attrs, '1', ($result==1)?TRUE:FALSE);
    echo form_label('Result 1', 'id_resultval_1');
echo '</p>';

Thanks for the assist!


Messages In This Thread
set_radio problem - by El Forum - 03-11-2013, 07:13 AM
set_radio problem - by El Forum - 03-11-2013, 08:13 AM
set_radio problem - by El Forum - 03-11-2013, 08:31 AM
set_radio problem - by El Forum - 03-12-2013, 01:45 AM
set_radio problem - by El Forum - 03-12-2013, 11:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB