* @version 0.9.4
* @license http://opensource.org/licenses/MIT MIT licensed.
*/
/*
===============================================================================================
USAGE
===============================================================================================
1. Load codeigniter 'form' helper --- $this->load->helper('form');
2. Load this library --- $this->load->library('form_builder');
3. Open your form (include the approprate class and col-sm-* for formating
4. Echo out the output of the form_builder->build_*
5. Close your form (`echo $this->form_builder->close_form()`).
6. Enjoy easy forms
-----------------------------------------------------------------------------------------------
$this->load->helper('form'); ?>
$this->load->library('form_builder'); ?>
echo $this->form_builder->open_form(array('action' => site_url('/account/login')));
echo $this->form_builder->build_form_horizontal(array(
array(
'id' => 'email',
'placeholder' => 'Email',
'type' => 'email'
),
array(
'id' => 'password',
'type' => 'password',
'placeholder' => 'Login Password'
),
array(
'id' => 'submit',
'type' => 'submit',
'label' => 'Login'
)
));
echo $this->form_builder->close_form();
?>
*/
class Form_builder {
private $config = array(/* Config array - can be overrided by passing in array in ini() */
'default_input_type' => 'form_input',
'default_input_container_class' => 'form-group',
'bootstrap_required_input_class' => 'form-control',
'default_dropdown_class' => 'valid',
'default_control_label_class' => 'col-sm-2 control-label',
'default_no_label_class' => 'col-sm-offset-2',
'default_form_control_class' => 'col-sm-9',
'default_form_class' => 'form-horizontal col-sm-12',
'default_button_classes' => 'btn btn-primary pull-right',
'default_date_post_addon' => '', // For instance ''
'default_date_format' => 'Y-m-d',
'default_date_today_if_not_set' => FALSE,
'default_datepicker_class' => '', // For instance 'date-picker'
'empty_value_html' => '
',
'use_testing_value' => true
);
private $func; /* Global function holder - used in switches */
private $data_source; /* Global holder for the source of the data */
private $elm_options; /* Global options holder */
private $elm_options_help;
private $print_string = ''; /* An output buffer */
/**
* @property array $input_addons
* This is for adding input-groups and addons.
* pre/post do not have to be inputed as arrays but will be turned into ones
* so that we can handle multipal pre/post input addons.
*/
private $input_addons = array(
'exists' => false, /* does the specific input have an addon? */
'pre' => array(), /* container for pre addons */
'pre_html' => '',
'post' => array(), /* container for post addons */
'post_html' => ''
);
private $CI;
function __construct($config = array()) {
$this->CI = &get_instance();
if (!empty($config)) {
$this->init($config);
} else {
$this->func = $this->config['default_input_type'];
}
}
function init($config = array()) {
if (!empty($config)) {
foreach ($config as $k => $v) {
$this->config[$k] = $v;
}
$this->func = $this->config['default_input_type'];
}
}
function get_config() {
return $this->config;
}
function open_form($options) {
//