Welcome Guest, Not a member yet? Register   Sign In
Possible bug in set_checkbox() function in form_helper library
#1

[eluser]krif[/eluser]
It might be me using the function wrong but when I call the set_checkbox of the Form Helper library without having post variables yet, it always returns a 'checked="checked"'

As far as I see it, the problem is that the function checks if set_checkbox() has not yet been defined by the Form Validation library yet, then looks for the validation object and post field data but if all those return FALSE or 0 resp. then returns checked even if the third parameter was set to FALSE or not defined.

This is the original code:

Code:
if ( ! function_exists('set_checkbox'))
{
    function set_checkbox($field = '', $value = '', $default = FALSE)
    {
        $OBJ =& _get_validation_object();

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

but I guess it should be more something like see the added "$default === TRUE AND " in line 11, or line 687 of the Form Helper library in CI 1.7.0:

Code:
if ( ! function_exists('set_checkbox'))
{
    function set_checkbox($field = '', $value = '', $default = FALSE)
    {
        $OBJ =& _get_validation_object();

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


Messages In This Thread
Possible bug in set_checkbox() function in form_helper library - by El Forum - 02-01-2009, 08:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB