Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Issue with Form::radio when radio value is 0
  • Hi guys,
    I'm loving the framework. Thanks for all your work on it.

    It looks like I may have found a bug in the Form::radio function. I'm not sure if this is known already or not. I'm using Fuelphp 1.4.

    Here's my code:
    <code>test: <?php echo Form::radio('public', '0', false); ?></code>

    This returns the following html:
    <code><input id="form_public" type="radio" checked="checked" value="0" name="public"></code>

    Passing '0' as the second (value) param and boolean false as the third (checked) param results in a checked radio button. It looks like the offending bit of code is in core/classes/form/instance.php starting at line 300.

    <code>
                if ( ! is_array($checked))
                {
                    // If it's true, then go for it
                    if (is_bool($checked) and $checked === true)
                    {
                        $attributes['checked'] = 'checked';
                    }

                    // Otherwise, if the string/number/whatever matches then do it
                    elseif (is_scalar($checked) and $checked == $value)
                    {
                        $attributes['checked'] = 'checked';
                    }
                }
    </code>

    Moving the check for true inside the is_bool if statement seems to solve the problem like this:
    <code>
    if (is_bool($checked))
    {
        if( $checked === true )
        {
            $attributes['checked'] = 'checked';
        }
    }
    </code>

    That way false booleans don't continue on to the is_scalar check.

    Am I doing something stupid (definitely a possibility) or is this actually a bug?

  • kesalikesali
    Accepted Answer
    Yes it is known bug. Update your FuelPHP to latest version.
  • Thanks Kesali. I guess I should have checked there first. It looks like it was fixed about a month ago in the 1.6 develop branch.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion