function set_attributes($attributes, $overwrite = true)
    {

        // check if $attributes is given as an array
        if (is_array($attributes))

            // iterate through the given attributes array
            foreach ($attributes as $attribute => $value) {

                // we need to url encode the prefix as it may contain HTML entities which would produce validation errors
                if ($attribute == 'data-prefix') $value = urlencode($value);

                // if the value is to be appended to the already existing one
                // and there is a value set for the specified attribute
                // and the values do not represent an array
                if (!$overwrite && isset($this->attributes[$attribute]) && !is_array($this->attributes[$attribute]))

                    // append the value
                    $this->attributes[$attribute] = $this->attributes[$attribute] . ' ' . $value;

                // otherwise, add attribute to attributes array
                else $this->attributes[$attribute] = $value;

            }

    }
function set_attributes($attributes, $overwrite = true)
    {

        // check if $attributes is given as an array
        if (is_array($attributes))

            // iterate through the given attributes array
            foreach ($attributes as $attribute => $value) {

                // we need to url encode the prefix as it may contain HTML entities which would produce validation errors
                if ($attribute == 'data-prefix') $value = urlencode($value);

                // if the value is to be appended to the already existing one
                // and there is a value set for the specified attribute
                // and the values do not represent an array
                if (!$overwrite && isset($this->attributes[$attribute]) && !is_array($this->attributes[$attribute]))

                    // append the value
                    $this->attributes[$attribute] = $this->attributes[$attribute] . ' ' . $value;

                // otherwise, add attribute to attributes array
                else $this->attributes[$attribute] = $value;

            }

    }
function set_attributes ( $ attributes , $ overwrite = true ) { // check if $attributes is given as an array if ( is_array ( $ attributes ) ) // iterate through the given attributes array foreach ( $ attributes as $ attribute => $ value ) { // we need to url encode the prefix as it may contain HTML entities which would produce validation errors if ( $ attribute == 'data-prefix' ) $ value = urlencode ( $ value ) ; // if the value is to be appended to the already existing one // and there is a value set for the specified attribute // and the values do not represent an array if ( ! $ overwrite && isset ( $ this -> attributes [ $ attribute ] ) && ! is_array ( $ this -> attributes [ $ attribute ] ) ) // append the value $ this -> attributes [ $ attribute ] = $ this -> attributes [ $ attribute ] . ' ' . $ value ; // otherwise, add attribute to attributes array else $ this -> attributes [ $ attribute ] = $ value ; } }
Sets one or more of the control's attributes.

<code>
// create a new form
$form = new Zebra_Form('my_form');

// add a text field to the form
$obj = $form->add('text', 'my_text');

// set some attributes for the text field
$obj->set_attributes(array(
'readonly'  => 'readonly',
'style'     => 'font-size:20px',
));

// retrieve the attributes
$attributes = $obj->get_attributes(array('readonly', 'style'));

// the result will be an associative array
//
// $attributes = Array(
//      [readonly]  => "readonly",
//      [style]     => "font-size:20px"
// )
</code>

@param  array       $attributes     An associative array, in the form of <i>attribute => value</i>.

@param  boolean     $overwrite      Setting this argument to FALSE will instruct the script to append the values
of the attributes to the already existing ones (if any) rather then overwriting
them.

Useful, for adding an extra CSS class to the already existing ones.

For example, the {@link Zebra_Form_Text text} control has, by default, the
<b>class</b> attribute set and already containing some classes needed both
for styling and for JavaScript functionality. If there's the need to add one
more class to the existing ones, without breaking styles nor functionality,
one would use:

<code>
// obj is a reference to a control
$obj->set_attributes(array('class'=>'my_class'), false);
</code>

Default is TRUE

@return void
Sets one or more of the control s attributes .