Welcome Guest, Not a member yet? Register   Sign In
Form Helper set_radio unexpected default value
#1

[eluser]jpi[/eluser]
Hi,
From line 749 file form_helper.php
Code:
function set_radio($field = '', $value = '', $default = FALSE)
    {
        $OBJ =& _get_validation_object();

        if ($OBJ === FALSE)
        {
            if ( ! isset($_POST[$field]))
            {
                if (count($_POST) === 0)
                {
                    return ' checked="checked"';
                }
                return '';
            }

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

            return ' checked="checked"';
        }

        return $OBJ->set_radio($field, $value, $default);
    }
Let's say I haven't initialized a form_validation object and have not yet submited the form that use set_radio() (so $_POST[] is empty). Then this function will return 'checked="checked"' whatever $default argument is.

I don't think it is the expected behavior.
#2

[eluser]fritzthecat[/eluser]
IAWTP - surely if $_POST is empty the function should use $default
#3

[eluser]Muser[/eluser]
I think it is a bug too. I am using Codeigniter 1.7.1 and for all the radios the attribute checked="checked" is parsed.




Theme © iAndrew 2016 - Forum software by © MyBB