Form Generation Library


Replace vs. Combine

Multi-value attributes (class, style and javascript events starting with on...) can be either replaced or combined with the $config['defaults'] and $config['globals'] values provided in the Config File. Replacement will be performed in the following hierarchical order:

value set in element tag

will replace

value set in $config['defaults'] for specific element name

will replace

value set in $config['defaults'] for general element type

will replace

value set in $config['globals']

Class

If $config['replace'] is set to TRUE for classes, they will be replaced in hierarchical order. If it is set to FALSE all classes will be combined.

Controller

$this->form->text('city', 'City', '', '', 'class=d');

Config File

$config['globals'] = array('class' => 'a');
$config['defaults'] = array(
   'text' => array('class' => 'b'),
   'city' => array('class' => 'c')
);

Output

// $config['replace'] = FALSE
<input type="text" name="city" class="a b c d" /> // all values are being combined

// $config['replace'] = TRUE
<input type="text" name="city" class="d" /> // values are being replaced in hierarchical order

Style

If $config['replace'] is set to TRUE for styles, values for the same style will be replaced in hierarchical order. If set to FALSE previously set values will be preserved.

Controller

$this->form->text('city', 'City', '', '', 'style=margin:10px');

Config File

$config['globals'] = array('style' => 'color:#666');
$config['defaults'] = array(
   'text' => array('style' => 'margin:20px; padding:10px'),
   'city' => array('style' => 'padding:30px')
);

Output

// $config['replace'] = FALSE
<input type="text" name="city" style="margin:20px; padding:10px; color:#666" /> // margin supplied with defaults, padding supplied with defaults, color from globals

// $config['replace'] = TRUE
<input type="text" name="city" style="margin:10px; padding:30px; color:#666" /> // margin replaced in element, padding replaced in speficic default, color from globals

JavaScript

If replace is set to TRUE for scripts, values for the same event will be replaced in hierarchical order. If it is set to FALSE all values will be combined.

Controller

$this->form->text('city', 'City', '', '', "onmouseover=alert('element')");

Config File

$config['defaults'] = array(
   'text' => array('onmouseover' => "alert('default > type')"),
   'city' => array('onmouseover' => "alert('default > element')")
);

Output

// $config['replace'] = FALSE
<input type="text" name="city" onmouseover="alert('default > type'); alert('default > element'); alert('element');" /> // all values are being combined

// $config['replace'] = TRUE
<input type="text" name="city" onmouseover="alert('element')" /> // values are being replaced in hierarchical order