Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
array_to_attr and HTML5 valueless attributes
  • HTML5 tags include a number of valueless attributes, and the array_to_attr function from base.php does not seem to handle them appropriately. For example, the script tag has the attributes async and defer, neither of which require a value to be set.

    At present the only way to pass these attributes is in the form attr="attr", which is valid in XHTML but against HTML5. It seems as if the array_to_attr function could fairly easily be made to handle these by using a value of null (it currently ignores keys in the passed array with a null value).

    I'm definitely willing to create a pull request with this but wanted to check first to see if there's a specific design reason it functions this way?
  • HarroHarro
    Accepted Answer
    It was written with XHTML in mind, and never updated.

    I suggest to add an additional argument, to not break any backward compatibility:

    function array_to_attr($attr, $html5 = false)

    and then do something like this?

    // deal with null and bool values
    if (is_null($value) or is_bool($value))
    {
        if ($html5)
        {
            $attr_str .= $property.' ';
        }
        continue;
    }

    In other words, if the value can not be "printed", only add the property. It doesn't really matter if it's null, false or true.

Howdy, Stranger!

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

In this Discussion