Form Generation Library


Config File

Important: The config file syntax has changed with version 1.0. Please update your library and config files accordingly!

The configuration file contains various settings for the form code output. A detailed explanation of all settings will follow this config file code example.

$config[nameasid] = TRUE;
$config['replace'] = 'TRUE|TRUE|TRUE';
$config['xss_clean_post'] = TRUE;

$config['group_prefix'] = '';
$config['group_suffix'] = '';
$config['element_prefix'] = '';
$config['element_suffix'] = '<br />';
$config['label_prefix'] = '';
$config['label_suffix'] = '';
$config['field_prefix'] = '';
$config['field_suffix'] = '';

$config['error_open'] = '<div>- ';
$config['error_close'] = '</div>';
$config['error_string_open'] = '<div id="errors">';
$config['error_string_close'] = '</div>';
$config['error_class'] = 'error';
$config['error_inline'] = FALSE;
$config['error_inline_open'] = '';
$config['error_inline_close'] = '';
$config['error_flag'] = '<img src="'.base_url().'images/error.png" />';

$config['globals'] = array();
$config['defaults'] = array();

$config['recaptcha_api_server'] = 'http://api.recaptcha.net';
$config['recaptcha_api_secure_server'] = 'https://api-secure.recaptcha.net';
$config['recaptcha_ssl'] = 'FALSE';
$config['recaptcha_verify_server'] = 'api-verify.recaptcha.net';
$config['recaptcha_key_public'] = '';
$config['recaptcha_key_private'] = '';
$config['recaptcha_theme'] = 'white';
$config['recaptcha_lang'] = 'en';

Note: The config file must be named form.php and saved to /applications/config

General Settings

$config['nameasid'] = BOOL

If set to TRUE the library will add an id attribute with the value of the name attribute for all appropriate elements. $form->text('city|city', 'City');

// equals

$form->text('city', 'City'); // with $config['nameasid'] = TRUE in the config file

$config['replace'] = 'BOOL|BOOL|BOOL'

If set to TRUE all multi-value attributes for classes, styles and scripts set in $config['globals'] and $config['defaults'] will be replaced in hierarchical order. Please see Replace vs. Combine for further details. $config['overwrite'] = 'FALSE|TRUE|TRUE'; // combine classes, overwrite styles and javascript events

$config['xss_clean_post'] = BOOL

If set to TRUE all post variables fetched via $this->form->get_post() will be XSS cleaned.

Prefix/Suffix Settings

These settings allow to automatically add prefixes and suffixes for groups (checkgroup/radiogroup), elements as well as the element's label and field.

To learn more about how to use this setting please read the Prefixes/Suffixes section of the user guide.

Error Settings

$config['error_open'] = '<div>- '
$config['error_close'] = '</div>'

Sets the opening and closing tags for each error message.

$config['error_string_open'] = '<div class="error">'
$config['error_string_close'] = '</div>'

Sets the opening and closing tags to wrap all errors returned by $form->error after the form was validated.

Example

// echo $form->errors outputs:

<div class="error">
<div>- The Zip code must only contain numbers</div>
<div>- The password field is required</div>
</div>

$config['error_class'] = 'error'

If set, will add this class to all elements that did not pass their validation rules. Very useful if you want to change the border color of text inputs to red upon errors.

$config['error_inline'] = BOOL

If set to TRUE, error messages will be displayed inline after the element.

$config['error_inline_open'] = '<span class="red">'
$config['error_inline_close'] = '</span>'

Sets the opening and closing tags for inline error messages.

$config['error_inline_flag'] = '<img src="../images/error.png" alt="{error}" title="{error}" />'

If set, this code will be added after the element instead of the error message. Very useful if you want to indicate an error with an image.
You can use the placeholder {error} to include the actual error message in your code.

Global Values

With this setting you can define attributes that will be added to every element in the form. $config['globals'] = array(
   'style' => 'background-color: #bbb'
);

Note: Before using this you should consider making global changes in your CSS file rather than in the config file.

Default Values

With this setting you can define attributes that will be added to elements in the form. You can define them by either specifying an element type (text, radiogroup, etc) or by providing a specific element name. This reduces your code in the controller and makes your elements easily re-usable in other forms. Please do consider that for adding styles you should always use stylesheets over these settings in the config file. $config['defaults'] = array(
     // define default values for element types
   'text' => array(
      'class' => 'text',
      'rules' => 'trim^xss_clean'
   ),
   'upload' => array(
      'upload_path' => './uploads',
      'allowed_types' => 'pdf|doc|jpg|gif',
      'rules' => 'required'
   ),
     // define default values for specific elements
   'file_upload' => array(
      'err_message' => 'The File Upload is required and must be either pdf, doc, jpg or gif.'
   )
);

Note: To preserve the replacement hierarchy you should always define $config['globals'] first, then $config['defaults'] for element types and then $config['defaults'] for specific elements.

Multiple Config File Settings

You can use multiple config file settings by simply providing config variables as arrays. Please note that only ALL of the config values for $config[1] (= default configuration) must be defined. If config values for other keys are missing the library will automatically use the corresponding value of $config[1]. So you only need to configure differences to the default configuration.

$config[1]['nameasid'] = FALSE;
$config[1]['overwrite'] = FALSE|TRUE|TRUE;
...

$config[2]['nameasid'] = TRUE;
$config[2]['overwrite'] = FALSE;
...

In the controller you will need to let the form know which config setting to load:

$this->form
->config(1)
...

Note: The array index has to start with 1, then 2, 3 ...