├── images └── form_render_screen_shot.png ├── examples ├── address_form │ ├── bootstrap_3_address_form.png │ ├── README.md │ └── bootstrap_3_address.php └── credit_card_form │ ├── bootstrap_3_credit_card_form.png │ ├── README.md │ └── bootstrap_3_credit_card ├── LICENSE ├── README.md └── application └── libraries └── form_builder.php /images/form_render_screen_shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wallter/codeigniter_bootstrap_form_builder/HEAD/images/form_render_screen_shot.png -------------------------------------------------------------------------------- /examples/address_form/bootstrap_3_address_form.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wallter/codeigniter_bootstrap_form_builder/HEAD/examples/address_form/bootstrap_3_address_form.png -------------------------------------------------------------------------------- /examples/credit_card_form/bootstrap_3_credit_card_form.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wallter/codeigniter_bootstrap_form_builder/HEAD/examples/credit_card_form/bootstrap_3_credit_card_form.png -------------------------------------------------------------------------------- /examples/credit_card_form/README.md: -------------------------------------------------------------------------------- 1 | Codeigniter Bootstrap 3 - Credit Card Form 2 | ====================== 3 | 4 | Notes: I am using the select2 JavaScript plugin for the select box styling - get it here: http://ivaynberg.github.io/select2/ 5 | 6 | Call this view like this: 7 | 8 |

Credit Card Info

9 | load->view('store/template/bootstrap_3_credit_card'); ?> 10 | 11 | ![ScreenShot](https://raw.github.com/wallter/codeigniter_bootstrap_form_builder/master/examples/credit_card_form/bootstrap_3_credit_card_form.png) 12 | -------------------------------------------------------------------------------- /examples/address_form/README.md: -------------------------------------------------------------------------------- 1 | Codeigniter Bootstrap 3 - Address Form 2 | ====================== 3 | 4 | Notes: I am using the select2 JavaScript plugin for the select box styling - get it here: http://ivaynberg.github.io/select2/ 5 | 6 | Call this view like this: 7 | 8 |

Shipping Address

9 | load->view('store/template/bootstrap_3_address', array('prefix' => 'shipping_')); ?> 10 | 11 | ![ScreenShot](https://raw.github.com/wallter/codeigniter_bootstrap_form_builder/master/examples/address_form/bootstrap_3_address_form.png) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Tyler Wall 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/credit_card_form/bootstrap_3_credit_card: -------------------------------------------------------------------------------- 1 | load->view('store/template/bootstrap_3_credit_card', array('input_span' => 'col-md-3'); 15 | * 16 | */ 17 | 18 | $input_span = (isset($input_span)) ? $input_span . ' ' : ''; 19 | 20 | /* Begin building form */ 21 | 22 | $yearRange = 10; 23 | $thisYear = date('Y'); 24 | $startYear = ($thisYear + 10); 25 | 26 | $exp_year_options = array(); 27 | foreach (range($thisYear, $startYear) as $year) { 28 | $exp_year_options[$year] = $year; 29 | } 30 | 31 | $form_options = array( 32 | array( 33 | 'id' => 'cc_owner', 34 | 'label' => 'Name', 35 | 'placeholder' => 'The Name on the Credit Card', 36 | 'class' => $input_span . 'required', 37 | 'required' => '', 38 | 'autocomplete' => 'cc-name', 39 | 'value' => isset($cc_owner) ? $cc_owner : '' 40 | ), 41 | array( 42 | 'id' => 'cc_type', 43 | 'label' => 'Card Type', 44 | 'type' => 'dropdown', 45 | 'options' => array( 46 | 'visa' => 'Visa', 47 | 'master card' => 'Master Card', 48 | 'discover' => 'Discover', 49 | 'american express' => 'American Express' 50 | ), 51 | 'autocomplete' => 'cc-type', 52 | 'class' => $input_span . 'required input-medium', 53 | 'required' => '', 54 | 'value' => isset($cc_type) ? $cc_type : '' 55 | ), 56 | array( 57 | 'id' => 'cc_number', 58 | 'label' => 'Card Number', 59 | 'autocomplete' => 'cc-number', 60 | 'class' => $input_span . 'required', 61 | 'required' => '', 62 | 'maxlength' => '19', 63 | 'minlength' => '12', 64 | 'pattern' => '(\d\s?){13,16}', 65 | 'value' => isset($cc_number) ? $cc_number : '' 66 | ), 67 | array( 68 | 'id' => 'experation_date', 69 | 'type' => 'combine', 70 | 'elements' => array( 71 | array( 72 | 'id' => 'cc_exp_month', 73 | 'label' => 'Expiration Date', 74 | 'autocomplete' => 'cc-exp-month', 75 | 'type' => 'dropdown', 76 | 'options' => array( 77 | '01' => '01 - Jan', 78 | '02' => '02 - Feb', 79 | '03' => '03 - Mar', 80 | '04' => '04 - Apr', 81 | '05' => '05 - May', 82 | '06' => '06 - June', 83 | '07' => '07 - July', 84 | '08' => '08 - Aug', 85 | '09' => '09 - Sept', 86 | '10' => '10 - Oct', 87 | '11' => '11 - Nov', 88 | '12' => '12 - Dec' 89 | ), 90 | 'class' => $input_span . 'required input-small', 91 | 'required' => '', 92 | 'data-items' => '4', 93 | 'pattern' => '\d{1,2}', 94 | 'style' => 'width: auto;', 95 | 'value' => (isset($cc_exp_month) ? $cc_exp_month : '') 96 | ), 97 | array( 98 | 'id' => 'cc_exp_year', 99 | 'label' => 'Expiration Date', 100 | 'autocomplete' => 'cc-exp-year', 101 | 'type' => 'dropdown', 102 | 'options' => $exp_year_options, 103 | 'class' => $input_span . 'required input-small', 104 | 'required' => '', 105 | 'data-items' => '4', 106 | 'pattern' => '\d{4}', 107 | 'style' => 'width: auto; margin-left: 5px;', 108 | 'value' => (isset($cc_exp_year) ? $cc_exp_year : '') 109 | ) 110 | ) 111 | ), 112 | array( 113 | 'id' => 'cc_cid', 114 | 'label' => 'CSC', 115 | 'autocomplete' => 'cc-csc', 116 | 'placeholder' => 'CSC', 117 | 'maxlength' => '4', 118 | 'minlength' => '3', 119 | 'class' => $input_span . 'required input-small', 120 | 'required' => '', 121 | 'style' => 'width: 3em;', 122 | 'pattern' => '\d+', 123 | 'value' => isset($cc_cid) ? $cc_cid : '' 124 | ) 125 | ); 126 | echo $this->form_builder->build_form_horizontal($form_options); 127 | ?> 128 | 129 | -------------------------------------------------------------------------------- /examples/address_form/bootstrap_3_address.php: -------------------------------------------------------------------------------- 1 | load->view('store/template/bootstrap_3_address', array('prefix' => 'shipping_')); 17 | * 18 | */ 19 | 20 | /* ===== Checking if Var's were passed into the file ===== */ 21 | $pref = (isset($prefix)) ? $prefix : ''; 22 | $group_sufx = (isset($prefix) && !empty($prefix)) ? str_replace('_', '', $prefix) : uniqid(); 23 | $input_span = (isset($input_span)) ? $input_span : ''; 24 | 25 | /* ===== BEGIN FORM BUILDING ===== */ 26 | 27 | $country_options = array(); 28 | $zone_options = array(); 29 | foreach ($this->store_service->get_countries() as $country) { 30 | $country_options[$country->id] = $country->name; 31 | } 32 | foreach ($this->store_service->get_zones_by_country((!empty($country_id) ? $country_id : '223')) as $zone) { 33 | $zone_options[$zone->id] = $zone->name; 34 | } 35 | 36 | $form_options = array( 37 | array( 38 | 'id' => $pref . 'first_name', 39 | 'autocomplete' => $group_sufx . ' given-name', 40 | 'placeholder' => 'First Name', 41 | 'label' => 'First Name', 42 | 'class' => $input_span, 43 | 'value' => !empty($first_name) ? $first_name : '' 44 | ), 45 | array( 46 | 'id' => $pref . 'last_name', 47 | 'autocomplete' => $group_sufx . ' family-name', 48 | 'placeholder' => 'Last Name', 49 | 'label' => 'Last Name', 50 | 'class' => $input_span, 51 | 'value' => !empty($last_name) ? $last_name : '' 52 | ), 53 | array( 54 | 'id' => $pref . 'phone', 55 | 'type' => 'tel', 56 | 'autocomplete' => $group_sufx . ' tel', 57 | 'placeholder' => 'Phone Number', 58 | 'label' => 'Phone', 59 | 'class' => $input_span, 60 | 'value' => !empty($phone) ? $phone : '' 61 | ), 62 | array( 63 | 'id' => $pref . 'email', 64 | 'type' => 'email', 65 | 'autocomplete' => $group_sufx . ' email', 66 | 'placeholder' => 'Email Address', 67 | 'label' => 'Email', 68 | 'class' => $input_span, 69 | 'value' => !empty($email) ? $email : '' 70 | ), 71 | array( 72 | 'id' => $pref . 'address1', 73 | 'autocomplete' => $group_sufx . ' address-line1', 74 | 'placeholder' => 'Address', 75 | 'label' => 'Address', 76 | 'class' => $input_span, 77 | 'value' => !empty($address1) ? $address1 : '' 78 | ), 79 | array( 80 | 'id' => $pref . 'address2', 81 | 'autocomplete' => $group_sufx . ' address-line2', 82 | 'placeholder' => 'Address 2nd line', 83 | 'label' => '', 84 | 'class' => $input_span, 85 | 'value' => !empty($address2) ? $address2 : '' 86 | ), 87 | array( 88 | 'id' => $pref . 'city', 89 | 'autocomplete' => $group_sufx . ' locality', 90 | 'placeholder' => 'City', 91 | 'label' => 'City', 92 | 'class' => $input_span, 93 | 'value' => !empty($city) ? $city : '' 94 | ), 95 | array( 96 | 'id' => $pref . 'country', 97 | 'label' => 'Country', 98 | 'autocomplete' => $group_sufx . ' country', 99 | 'class' => $input_span . ' input-medium', 100 | 'type' => 'dropdown', 101 | 'options' => $country_options, 102 | 'value' => (!empty($country_id)) ? $country_id : '223' 103 | ), 104 | array( 105 | 'id' => $pref . 'state', 106 | 'label' => 'State', 107 | 'autocomplete' => $group_sufx . ' region', 108 | 'class' => $input_span . ' input-medium', 109 | 'type' => 'dropdown', 110 | 'options' => $zone_options, 111 | 'value' => (!empty($state_id)) ? $state_id : 0 112 | ), 113 | array( 114 | 'id' => $pref . 'zip', 115 | 'label' => 'Zip Code', 116 | 'autocomplete' => $group_sufx . ' postal-code', 117 | 'placeholder' => 'Zip Code', 118 | 'class' => $input_span, 119 | 'value' => !empty($zip) ? $zip : '' 120 | ), 121 | ); 122 | /* Testing to make bootstrap 2 compatable - NOT WORKING */ 123 | //$this->form_builder->init(array( 124 | // 'default_control_label_class' => 'control-label', 125 | // 'default_input_container_class' => 'control-group', 126 | // 'default_form_control_class' => 'controls', 127 | // 'bootstrap_required_input_class' => '' 128 | //)); 129 | echo $this->form_builder->build_form_horizontal($form_options); 130 | ?> 131 | 132 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Codeigniter Bootstrap 3 Form Builder 2 | ====================== 3 | 4 | ### Do you want to write forms 60% faster? 5 | ### Or type 60% less? 6 | ### Are you using Codegniter and Bootstrap 3? 7 | ### Then this is the plugin for you! 8 | 9 | CodeIgniter library to build form's styled with Bootstrap 3. 10 | It's got 5 steps: 11 | * Load Libraries 12 | * Open Form 13 | * Echo out the output of your chosen function 14 | * Close your form 15 | * Enjoy Easy form building 16 | 17 | 18 | 1. Load Libraries 19 | ============== 20 | 21 | Load the Codeigniter form helper, then load the form_builder library. 22 | 23 | ``` 24 | $this->load->helper('form'); 25 | $this->load->library('form_builder'); 26 | ``` 27 | 28 | 2. Open Your form 29 | ============== 30 | 31 | ``` 32 | form_builder->open_form(array('action' => '')); ?> 33 | ``` 34 | 35 | 3. Echo out your form 36 | ============== 37 | 38 | ``` 39 | id = 33; 45 | $item->description = ''; 46 | 47 | $years = range(intval(date('Y')), intval(date('Y')) + 20); 48 | $months = array_map(function ($n) { 49 | return str_pad($n, 2, '0', STR_PAD_LEFT); 50 | }, range(1, 12)); 51 | 52 | $exp_month_options = array_combine($months, $months); 53 | $cc_exp_month = '05'; 54 | 55 | $exp_year_options = array_combine($years, $years); 56 | $cc_exp_year = intval(date('Y')) + 5; 57 | 58 | $input_span = 'pull-left '; 59 | 60 | /* Build form */ 61 | echo $this->form_builder->build_form_horizontal( 62 | array( 63 | array(/* HIDDEN */ 64 | 'id' => 'id', 65 | 'type' => 'hidden', 66 | 'value' => $item->id 67 | ), 68 | array(/* INPUT */ 69 | 'id' => 'color', 70 | 'placeholder' => 'Item Color', 71 | 'input_addons' => array( 72 | 'pre' => 'color: #', 73 | 'post' => ';' 74 | ), 75 | 'help' => 'this is a help block' 76 | ), 77 | array(/* DROP DOWN */ 78 | 'id' => 'published', 79 | 'type' => 'dropdown', 80 | 'options' => array( 81 | '1' => 'Published', 82 | '2' => 'Disabled' 83 | ) 84 | ), 85 | array(/* TEXTAREA */ 86 | 'id' => 'description', 87 | 'type' => 'textarea', 88 | 'class' => 'wysihtml5', 89 | 'placeholder' => 'Item Description (HTML or rich text)', 90 | 'value' => html_entity_decode($item->description) 91 | ), 92 | array(/* COMBINE */ 93 | 'id' => 'expiration_date', 94 | 'type' => 'combine', /* use `combine` to put several input inside the same block */ 95 | 'elements' => array( 96 | array( 97 | 'id' => 'cc_exp_month', 98 | 'label' => 'Expiration Date', 99 | 'autocomplete' => 'cc-exp-month', 100 | 'type' => 'dropdown', 101 | 'options' => $exp_month_options, 102 | 'class' => $input_span . 'required input-small', 103 | 'required' => '', 104 | 'data-items' => '4', 105 | 'pattern' => '\d{1,2}', 106 | 'style' => 'width: auto;', 107 | 'value' => (isset($cc_exp_month) ? $cc_exp_month : '') 108 | ), 109 | array( 110 | 'id' => 'cc_exp_year', 111 | 'label' => 'Expiration Date', 112 | 'autocomplete' => 'cc-exp-year', 113 | 'type' => 'dropdown', 114 | 'options' => $exp_year_options, 115 | 'class' => $input_span . 'required input-small', 116 | 'required' => '', 117 | 'data-items' => '4', 118 | 'pattern' => '\d{4}', 119 | 'style' => 'width: auto; margin-left: 5px;', 120 | 'value' => (isset($cc_exp_year) ? $cc_exp_year : '') 121 | ) 122 | ) 123 | ), 124 | array(/* DATE */ 125 | 'id' => 'date', 126 | 'type' => 'date' 127 | ), 128 | array(/* CHECKBOX */ 129 | 'id' => 'checkbox_group', 130 | 'label' => 'Checkboxes', 131 | 'type' => 'checkbox', 132 | 'options' => array( 133 | array( 134 | 'id' => 'checkbox1', 135 | 'value' => 1 136 | // If no label is set, the value will be used 137 | ), 138 | array( 139 | 'id' => 'checkbox2', 140 | 'value' => 2, 141 | 'label' => 'Two' 142 | ) 143 | ) 144 | ), 145 | array(/* RADIO */ 146 | 'id' => 'radio_group', 147 | 'label' => 'Radio buttons', 148 | 'type' => 'radio', 149 | 'options' => array( 150 | array( 151 | 'id' => 'radio_button_yes', 152 | 'value' => 1, 153 | 'label' => 'Yes' 154 | ), 155 | array( 156 | 'id' => 'radio_button_no', 157 | 'value' => 0, 158 | 'label' => 'No' 159 | ) 160 | ) 161 | ), 162 | array(/* SUBMIT */ 163 | 'id' => 'submit', 164 | 'type' => 'submit' 165 | ) 166 | ), $defaults_object_or_array_from_db); 167 | 168 | echo $this->form_builder->close_form(); 169 | ?> 170 | ``` 171 | 172 | 4. Close The Form 173 | ============== 174 | ``` 175 | form_builder->close_form(); ?> 176 | ``` 177 | 178 | Produces: 179 | ============== 180 | ``` 181 |
182 | 183 |
184 | 185 |
186 |
187 | color: # 188 | 189 | ; 190 |
191 | this is a help block 192 |
193 |
194 |
195 | 196 |
197 | 201 |
202 |
203 |
204 | 205 |
206 | 207 |
208 |
209 |
210 | 211 |
212 | 226 | 249 |
250 |
251 |
252 | 253 |
254 | 255 |
256 |
257 |
258 | 259 |
260 | 264 | 268 |
269 |
270 |
271 | 272 |
273 | 277 | 281 |
282 |
283 |
284 | 286 |
287 | 288 |
289 |
290 |
291 | ``` 292 | 293 | ![ScreenShot](https://raw.github.com/wallter/codeigniter_bootstrap_form_builder/master/images/form_render_screen_shot.png) 294 | -------------------------------------------------------------------------------- /application/libraries/form_builder.php: -------------------------------------------------------------------------------- 1 | 17 | * @version 0.9.4 18 | * @license http://opensource.org/licenses/MIT MIT licensed. 19 | */ 20 | /* 21 | =============================================================================================== 22 | USAGE 23 | =============================================================================================== 24 | 25 | 1. Load codeigniter 'form' helper --- $this->load->helper('form'); 26 | 2. Load this library --- $this->load->library('form_builder'); 27 | 3. Open your form (include the approprate class and col-sm-* for formating 28 | 4. Echo out the output of the form_builder->build_* 29 | 5. Close your form (`echo $this->form_builder->close_form()`). 30 | 6. Enjoy easy forms 31 | 32 | ----------------------------------------------------------------------------------------------- 33 | 34 | load->helper('form'); ?> 35 | load->library('form_builder'); ?> 36 | 37 | form_builder->open_form(array('action' => site_url('/account/login'))); 39 | echo $this->form_builder->build_form_horizontal(array( 40 | array( 41 | 'id' => 'email', 42 | 'placeholder' => 'Email', 43 | 'type' => 'email' 44 | ), 45 | array( 46 | 'id' => 'password', 47 | 'type' => 'password', 48 | 'placeholder' => 'Login Password' 49 | ), 50 | array( 51 | 'id' => 'submit', 52 | 'type' => 'submit', 53 | 'label' => 'Login' 54 | ) 55 | )); 56 | echo $this->form_builder->close_form(); 57 | ?> 58 | */ 59 | class Form_builder { 60 | 61 | private $config = array(/* Config array - can be overrided by passing in array in ini() */ 62 | 'default_input_type' => 'form_input', 63 | 'default_input_container_class' => 'form-group', 64 | 'bootstrap_required_input_class' => 'form-control', 65 | 'default_dropdown_class' => 'valid', 66 | 'default_control_label_class' => 'col-sm-2 control-label', 67 | 'default_no_label_class' => 'col-sm-offset-2', 68 | 'default_form_control_class' => 'col-sm-9', 69 | 'default_form_class' => 'form-horizontal col-sm-12', 70 | 'default_button_classes' => 'btn btn-primary', 71 | 'default_date_post_addon' => '', // For instance '' 72 | 'default_date_format' => 'Y-m-d', 73 | 'default_date_today_if_not_set' => FALSE, 74 | 'default_datepicker_class' => '', // For instance 'date-picker' 75 | 'empty_value_html' => '
', 76 | 'use_testing_value' => true 77 | ); 78 | private $func; /* Global function holder - used in switches */ 79 | private $data_source; /* Global holder for the source of the data */ 80 | private $elm_options; /* Global options holder */ 81 | private $elm_options_help; 82 | private $print_string = ''; /* An output buffer */ 83 | 84 | /** 85 | * @property array $input_addons 86 | * This is for adding input-groups and addons. 87 | * pre/post do not have to be inputed as arrays but will be turned into ones 88 | * so that we can handle multipal pre/post input addons. 89 | */ 90 | private $input_addons = array( 91 | 'exists' => false, /* does the specific input have an addon? */ 92 | 'pre' => array(), /* container for pre addons */ 93 | 'pre_html' => '', 94 | 'post' => array(), /* container for post addons */ 95 | 'post_html' => '' 96 | ); 97 | 98 | function __construct($config = array()) { 99 | if (!empty($config)) { 100 | $this->init($config); 101 | } else { 102 | $this->func = $this->config['default_input_type']; 103 | } 104 | } 105 | 106 | function init($config = array()) { 107 | if (!empty($config)) { 108 | foreach ($config as $k => $v) { 109 | $this->config[$k] = $v; 110 | } 111 | $this->func = $this->config['default_input_type']; 112 | } 113 | } 114 | 115 | function get_config() { 116 | return $this->config; 117 | } 118 | 119 | function open_form($options) { 120 | //
121 | $action = ''; 122 | if (isset($options['action'])) { 123 | $action = $options['action']; 124 | unset($options['action']); 125 | } else { 126 | show_error('No action set for form. Please include array(\'action\' => \'\') in the open_form(...) function call'); 127 | } 128 | 129 | $class = $this->config['default_form_class']; 130 | if (isset($options['class'])) { 131 | $class = $options['class']; 132 | } 133 | $options['class'] = $class; 134 | $options['autocomplete'] = 'on'; 135 | 136 | return $this->_build_form_open($action, $options); 137 | } 138 | 139 | function close_form() { 140 | return form_close(); 141 | } 142 | 143 | /** 144 | * 145 | * @param array $ary - an array from the DB. Format: $k => $v 146 | * @param array $custom_options - optional, an array that will override 147 | * the default values produced by this funciton 148 | * @return an array compatible with this class's `build_*` funcitons 149 | * @usage 150 | * $coupon_form_options = $this->form_builder->auto_db_to_options($coupon, array( 151 | * 'code' => array( 152 | * 'help' => 'The code the customer enters to get the discount' 153 | * ), 154 | * 'type' => array( 155 | * 'help' => 'Percentage or Fixed Amount', 156 | * 'type' => 'dropdown', 157 | * 'options' => array( 158 | * 'P' => 'Percentage', 159 | * 'F' => 'Fixed Amount' 160 | * ) 161 | * ) 162 | * )); 163 | */ 164 | function auto_db_to_options($ary, $custom_options = array()) { 165 | $options = array(); 166 | 167 | foreach ($ary as $k => $v) { 168 | $elm_options = array( 169 | 'id' => $k, 170 | 'value' => $v 171 | ); 172 | 173 | /* 174 | * TODO: this should be put in the options. It is suited specificaly for my database 175 | * configuration and my practices - which include having a 'id', 'modified', 'created', and 'active' 176 | * column in *ALL* databases - as well as some specific data. 177 | * 178 | * NOTE: This function will likely see a lot of change to make sure it is working and/or re-built 179 | * 'the right way' 180 | */ 181 | if (is_json($v)) { 182 | $elm_options['type'] = 'json'; 183 | } else { 184 | /* the key contains 'date' - if it does lets assume that it should be a date */ 185 | if (strpos(strtolower($k), 'date') !== FALSE) { 186 | $k = 'date'; 187 | } 188 | switch ($k) { 189 | case 'id': 190 | $elm_options['readonly'] = 'readonly'; 191 | break; 192 | case 'date': 193 | $elm_options['type'] = 'date'; 194 | break; 195 | case 'modified': 196 | case 'created': 197 | $elm_options['type'] = 'date'; 198 | $elm_options['readonly'] = 'readonly'; 199 | break; 200 | case 'active': 201 | $elm_options['type'] = 'dropdown'; 202 | $elm_options['options'] = array( 203 | '1' => 'Active', 204 | '0' => 'De-Active' 205 | ); 206 | $elm_options['readonly'] = 'readonly'; 207 | break; 208 | case 'log': 209 | $elm_options['type'] = 'json'; 210 | break; 211 | } 212 | } 213 | 214 | /* We need to override what was 'auto' created - Note: should always be done last */ 215 | if (isset($custom_options) && isset($custom_options[$k])) { 216 | if (is_array($custom_options[$k])) { 217 | $elm_options = array_merge($elm_options, $custom_options[$k]); 218 | } 219 | } 220 | 221 | if (!(isset($custom_options) && isset($custom_options[$k]) && !is_array($custom_options[$k]) && $custom_options[$k] == 'unset')) { 222 | $options[] = $elm_options; 223 | } 224 | } 225 | 226 | return $options; 227 | } 228 | 229 | /** 230 | * 231 | * @param array $pre_built - the array that was pre-built using `auto_db_to_options` 232 | * @param string $id - the id/name of the element to add to 233 | * @param array $vals_ary - an array of new (or over-riding) values 234 | * @return none 235 | * 236 | * @usage 237 | * $this->form_builder->change_pre_built($coupon_form_options, 'type', array( 238 | * 'help' => 'Percentage or Fixed Amount', 239 | * 'type' => 'dropdown', 240 | * 'options' => array( 241 | * 'P' => 'Percentage', 242 | * 'F' => 'Fixed Amount' 243 | * ) 244 | * )); 245 | * 246 | * @notes The same effect can be gained when calling `auto_db_to_options` and passing 247 | * the 2nd paramater ($custom_options). But this is for the event that you need to do 248 | * custom / advanced changes. 249 | */ 250 | function change_pre_built(&$pre_built, $id, $vals_ary) { 251 | foreach ($pre_built as $k => $v) { 252 | if ($v['id'] == $id) { 253 | $pre_built[$k] = array_merge($pre_built[$k], $vals_ary); 254 | break; 255 | } 256 | } 257 | return; 258 | } 259 | 260 | /** 261 | * Build From Horizontal 262 | * @access public 263 | * @param Array - The array of options for the form. 264 | * @return form elements+wrappers HTML 265 | */ 266 | function build_form_horizontal($options, $data_source = array()) { 267 | $this->_reset_builder(); 268 | $this->data_source = (array) $data_source; 269 | 270 | foreach ($options as $elm_options) { 271 | $this->elm_options = $elm_options; 272 | 273 | if (is_array($this->elm_options)) { 274 | $this->_prep_options(); 275 | switch ($this->func) { 276 | case 'form_hidden': 277 | $this->print_string .= $this->_build_input(); 278 | break; 279 | case 'form_checkbox': 280 | case 'form_radio': 281 | // Link main label to input when there is only one option and that option has an empty label 282 | $link_to_input = ((count($this->elm_options['options']) === 1) && array_key_exists('label', $this->elm_options['options'][0]) && ($this->elm_options['options'][0]['label'] === '')); 283 | 284 | $default_form_control_class = $this->config['default_form_control_class']; 285 | if (!array_key_exists('label', $this->elm_options) || ($this->elm_options['label'] === 'none')) 286 | { 287 | $this->config['default_form_control_class'] .= ' '.$this->config['default_no_label_class']; 288 | } 289 | 290 | $this->print_string .= $this->_pre_elm(); 291 | $this->print_string .= $this->_label($link_to_input); 292 | $this->print_string .= $this->_pre_input(); 293 | 294 | $this->config['default_form_control_class'] = $default_form_control_class; 295 | 296 | $all_elm_options = $this->elm_options; 297 | 298 | foreach ($all_elm_options['options'] as $elm_suboptions) { 299 | $this->elm_options = $elm_suboptions; 300 | $this->elm_options['name'] = $all_elm_options['name']; 301 | $this->elm_options['id'] = $all_elm_options['id']; 302 | 303 | // Set value as label if no label is set 304 | array_key_exists('label', $this->elm_options) || $this->elm_options['label'] = $this->elm_options['value']; 305 | 306 | $label_class = substr($this->func, 5).'-inline'; 307 | array_key_exists('disabled', $this->elm_options) && $label_class .= ' disabled'; 308 | 309 | $this->print_string .= ''; // Place a nbps to keep the radio button / checkbox aligned with the main label 312 | } 313 | 314 | $this->print_string .= $this->_post_input(); 315 | $this->print_string .= $this->_post_elm(); 316 | 317 | $this->elm_options = $all_elm_options; 318 | break; 319 | default: 320 | $this->print_string .= $this->_pre_elm(); 321 | $this->print_string .= $this->_label(); 322 | $this->print_string .= $this->_build_input(); 323 | $this->print_string .= $this->_post_elm(); 324 | break; 325 | } 326 | } 327 | } 328 | return $this->squish_HTML($this->print_string); 329 | } 330 | 331 | /** 332 | * Function build_display 333 | * 334 | * Function is to build a viewable form using the easy form builder. 335 | * Includes token form_open and form_close just to make sure all the styling 336 | * works correctly. 337 | * 338 | * @param array $options - the elements/options for the form elemnts being built. 339 | * @param array/object $data_source - a default source for the value 340 | * @return string - the elements 341 | */ 342 | function build_display($options, $data_source = array()) { 343 | $this->_reset_builder(); 344 | $this->data_source = (array) $data_source; 345 | 346 | /* styling prefrence */ 347 | $this->config['default_control_label_class'] .= ' bold'; 348 | 349 | $this->print_string .= $this->_build_form_open('', array('class' => $this->config['default_form_class'])); 350 | 351 | foreach ($options as $elm_options) { 352 | $this->elm_options = $elm_options; 353 | 354 | if (is_array($this->elm_options)) { 355 | $this->_prep_options(); 356 | if ($this->func != 'form_json') { 357 | $this->func = 'form_label'; /* The only difference */ 358 | } 359 | $this->print_string .= $this->_pre_elm(); 360 | $this->print_string .= $this->_label(); 361 | $this->print_string .= $this->_build_input(); 362 | $this->print_string .= $this->_post_elm(); 363 | } 364 | } 365 | $this->print_string .= $this->close_form(); 366 | return $this->squish_HTML($this->print_string); 367 | } 368 | 369 | private function _prep_options() { 370 | foreach ($this->elm_options as &$opt) { 371 | /* trying again to change everything to an array */ 372 | if (is_object($opt)) { 373 | $opt = (array) $opt; 374 | } 375 | } 376 | $this->func = $this->config['default_input_type']; 377 | /* Pull the input type from the array */ 378 | if (isset($this->elm_options['type']) && !empty($this->elm_options['type'])) { 379 | $this->func = 'form_' . $this->elm_options['type']; 380 | unset($this->elm_options['type']); 381 | } else { 382 | $this->func = $this->config['default_input_type']; 383 | } 384 | // TODO: add some error checking that checks this function 385 | // if (!function_exists($this->func)) { /* check if the function exists */ 386 | // $this->func = $this->config['default_input_type']; 387 | // } 388 | 389 | /* make sure to add 'form-control' to the class array */ 390 | $class = $this->config['bootstrap_required_input_class']; 391 | if (isset($this->elm_options['class'])) { 392 | $class .= ' ' . trim(str_replace($this->config['bootstrap_required_input_class'], '', $this->elm_options['class'])); 393 | } 394 | $this->elm_options['class'] = $class; 395 | 396 | /* make sure there is a name' attribute */ 397 | if (!isset($this->elm_options['name'])) { 398 | /* put the id as the name by default - makes smaller 'config' arrays */ 399 | if (isset($this->elm_options['id'])) { 400 | $this->elm_options['name'] = $this->elm_options['id']; 401 | } else { 402 | $this->elm_options['name'] = ''; 403 | } 404 | } 405 | 406 | /* make sure there is a 'value' attribute 407 | * Also, make for fun defaulting by passing an object 408 | */ 409 | $default_value = ''; 410 | if (isset($this->elm_options['name']) && isset($this->data_source[$this->elm_options['name']]) && empty($this->elm_options['value'])) { 411 | $default_value = $this->data_source[$this->elm_options['name']]; 412 | } elseif (isset($this->elm_options['value'])) { 413 | $default_value = $this->elm_options['value']; 414 | } 415 | 416 | if (isset($this->elm_options['testing_value']) && $this->config['use_testing_value']) { 417 | $default_value = $this->elm_options['testing_value']; 418 | } 419 | 420 | $this->elm_options['value'] = $this->adv_set_value($this->elm_options['name'], $default_value); 421 | 422 | 423 | /* ====== Handle input_addons ======== */ 424 | 425 | /* FIRST - clear the input_addons global array from any previous elemets */ 426 | $this->input_addons = array( 427 | 'exists' => false, 428 | 'pre' => array(), 429 | 'pre_html' => '', 430 | 'post' => array(), 431 | 'post_html' => '' 432 | ); 433 | 434 | /* playing nice: handling the singular case */ 435 | if (isset($this->elm_options['input_addon'])) { 436 | $this->elm_options['input_addons'] = $this->elm_options['input_addon']; 437 | unset($this->elm_options['input_addon']); 438 | } 439 | 440 | /* set the new input_addons array */ 441 | if (isset($this->elm_options['input_addons']) && !empty($this->elm_options['input_addons'])) { 442 | /* there are input addons */ 443 | $this->input_addons['exists'] = true; 444 | 445 | /* check for pre addons */ 446 | if (isset($this->elm_options['input_addons']['pre']) && !empty($this->elm_options['input_addons']['pre'])) { 447 | $pre = $this->elm_options['input_addons']['pre']; 448 | if (!is_array($pre)) { /* to handle more than one, this needs to be an array - but should handle the easy case of one string */ 449 | $pre = array($pre); 450 | } 451 | $this->input_addons['pre'] = $pre; 452 | } 453 | 454 | /* then check for post addons */ 455 | if (isset($this->elm_options['input_addons']['post']) && !empty($this->elm_options['input_addons']['post'])) { 456 | $post = $this->elm_options['input_addons']['post']; 457 | if (!is_array($post)) { /* to handle more than one, this needs to be an array - but should handle the easy case of one string */ 458 | $post = array($post); 459 | } 460 | $this->input_addons['post'] = $post; 461 | } 462 | 463 | /* accomidate hard coding of custom elements */ 464 | if (isset($this->elm_options['input_addons']['pre_html']) && !empty($this->elm_options['input_addons']['pre_html'])) { 465 | $this->input_addons['pre_html'] = $this->elm_options['input_addons']['pre_html']; 466 | } 467 | if (isset($this->elm_options['input_addons']['post_html']) && !empty($this->elm_options['input_addons']['post_html'])) { 468 | $this->input_addons['post_html'] = $this->elm_options['input_addons']['post_html']; 469 | } 470 | 471 | 472 | /* unset it so that no funky stuff happens */ 473 | unset($this->elm_options['input_addons']); 474 | } 475 | 476 | /* remove help element - don't need help properties to be in input elements */ 477 | $this->elm_options_help = (isset($this->elm_options['help']) && !empty($this->elm_options['help'])) ? $this->elm_options['help'] : ''; 478 | unset($this->elm_options['help']); 479 | return; 480 | } 481 | 482 | /** 483 | * Form Value 484 | * 485 | * Upgraded from Codeigniter Form Helper 486 | * 487 | * Grabs a value from the POST or GET array for the specified field so you can 488 | * re-populate an input field or textarea. If Form Validation 489 | * is active it retrieves the info from the validation class 490 | * 491 | * @access public 492 | * @param string 493 | * @return mixed 494 | * @author ExpressionEngine Dev Team 495 | * @author Tyler Wall 496 | */ 497 | function adv_set_value($field = '', $default = '') { 498 | if (FALSE === ($OBJ = & _get_validation_object())) { 499 | if (isset($_POST[$field])) { 500 | return html_escape($_POST[$field]); 501 | } elseif (isset($_GET[$field])) { 502 | return html_escape($_GET[$field]); 503 | } 504 | return $default; 505 | } 506 | 507 | return html_escape($OBJ->set_value($field, $default)); 508 | } 509 | 510 | function squish_HTML($html) { 511 | $re = '%# Collapse whitespace everywhere but in blacklisted elements. 512 | (?> # Match all whitespans other than single space. 513 | [^\S ]\s* # Either one [\t\r\n\f\v] and zero or more ws, 514 | | \s{2,} # or two or more consecutive-any-whitespace. 515 | ) # Note: The remaining regex consumes no text at all... 516 | (?= # Ensure we are not in a blacklist tag. 517 | [^<]*+ # Either zero or more non-"<" {normal*} 518 | (?: # Begin {(special normal*)*} construct 519 | < # or a < starting a non-blacklist tag. 520 | (?!/?(?:textarea|pre|script)\b) 521 | [^<]*+ # more non-"<" {normal*} 522 | )*+ # Finish "unrolling-the-loop" 523 | (?: # Begin alternation group. 524 | < # Either a blacklist start tag. 525 | (?>textarea|pre|script)\b 526 | | \z # or end of file. 527 | ) # End alternation group. 528 | ) # If we made it here, we are not in a blacklist tag. 529 | %Six'; 530 | $text = preg_replace($re, " ", $html); 531 | if ($text === null) { 532 | return $html; 533 | } 534 | return $text; 535 | } 536 | 537 | /* 538 | =============================================================================================== 539 | PRIVATE FUNCTIONS 540 | =============================================================================================== 541 | */ 542 | 543 | private function _build_input($include_pre_post = true) { 544 | $input_html_string = ''; 545 | /* Combine elements have multiple input elements on the same line. 546 | * This block will call this function, '_build_input' call recursivly. 547 | * 548 | * Example use: Credit Card EXP month/year 549 | */ 550 | if ($this->func == 'form_combine') { 551 | if (!isset($this->elm_options['elements'])) { 552 | dump($this->elm_options); 553 | show_error('Tried to create `form_combine` with no elements. (id="' . $this->elm_options['name'] . '")'); 554 | } 555 | 556 | $elm_options_backup = $this->elm_options; /* We need to make a copy for everything to work correctly */ 557 | 558 | $counter = 0; 559 | foreach ($elm_options_backup['elements'] as $elm) { 560 | $this->elm_options = $elm; /* We override elm_options */ 561 | $this->_prep_options(); /* Run Prep on the new one */ 562 | if ($counter > 0 && !empty($elm_options_backup['combine_divider'])) { 563 | $input_html_string .= $elm_options_backup['combine_divider']; 564 | } 565 | $input_html_string .= $this->_build_input(false); 566 | $counter++; 567 | } 568 | 569 | $this->elm_options = $elm_options_backup; /* We put our options back */ 570 | $this->_prep_options(); /* Run Prep to restore the state in which we begain */ 571 | } else { 572 | /* 573 | * json 574 | * button (anchor, a) 575 | * label 576 | * date 577 | * email 578 | * tel 579 | * number 580 | * input 581 | * hidden 582 | * submit 583 | * dropdown (option) 584 | * html 585 | * textarea 586 | * file 587 | * checkbox 588 | * radio 589 | */ 590 | switch ($this->func) { 591 | /* 592 | * This should eventualy be expanded to be able to edit individual elements in the k=>v 593 | * For now it will just display them. 594 | */ 595 | case 'form_json': 596 | $input_html_string = $this->_recursive_build_json((array) json_decode($this->elm_options['value'])); 597 | break; 598 | case 'form_button': 599 | case 'form_anchor': 600 | case 'form_a': 601 | $class = str_replace($this->config['default_button_classes'], '', $this->elm_options['class']); 602 | $class = str_replace($this->config['bootstrap_required_input_class'], '', $class); /* remove the 'form-control' class */ 603 | /* add class="valid" to all dropdowns (makes them not full width - and works better with select2 plugin) */ 604 | if (strpos($class, $this->config['default_button_classes']) === FALSE) { 605 | $class .= ' ' . $this->config['default_button_classes']; 606 | } 607 | $this->elm_options['class'] = trim($class); 608 | 609 | $value = $this->elm_options['label']; 610 | unset($this->elm_options['label']); 611 | 612 | $input_html_string = anchor('', $value, $this->elm_options); 613 | break; 614 | case 'form_label': 615 | $input_html_string = form_label($this->_make_label($this->elm_options['value']), '', array( 616 | 'class' => 'control-label text-left' 617 | )); 618 | break; 619 | case 'form_date': 620 | $this->elm_options['type'] = 'date'; // HTML5 compliant type for date 621 | if ($this->config['default_date_post_addon'] != '') { 622 | $this->input_addons['exists'] = TRUE; 623 | $this->input_addons['post_html'] = $this->config['default_date_post_addon']; 624 | } 625 | 626 | try { 627 | if (empty($this->elm_options['value'])) { 628 | if ($this->config['default_date_today_if_not_set']) { 629 | $dt = new DateTime('today'); 630 | $this->elm_options['value'] = $dt->format($this->config['default_date_format']); 631 | } 632 | } else { 633 | $dt = new DateTime($this->elm_options['value']); 634 | $this->elm_options['value'] = $dt->format($this->config['default_date_format']); 635 | } 636 | } catch (Exception $e) { 637 | log_message('error', $e->getMessage().' at "'.$e->getFile().'" on line '.$e->getLine()); 638 | 639 | if ($this->config['default_date_today_if_not_set']) { 640 | $dt = new DateTime('today'); 641 | $this->elm_options['value'] = $dt->format($this->config['default_date_format']); 642 | } 643 | } 644 | 645 | $input_html_string = form_input($this->elm_options); 646 | break; 647 | case 'form_email': 648 | $this->elm_options['type'] = 'email'; 649 | $input_html_string = form_input($this->elm_options); 650 | break; 651 | case 'form_tel': 652 | $this->elm_options['type'] = 'tel'; 653 | $input_html_string = form_input($this->elm_options); 654 | break; 655 | case 'form_number': 656 | $this->elm_options['type'] = 'number'; 657 | $input_html_string = form_input($this->elm_options); 658 | break; 659 | case 'form_input': 660 | $input_html_string = form_input($this->elm_options); 661 | break; 662 | case 'form_hidden': 663 | return form_hidden($this->elm_options['id'], $this->elm_options['value']); 664 | case 'form_submit': 665 | $name = $this->elm_options['id']; 666 | $label = $this->_make_label((isset($this->elm_options['label']) ? $this->elm_options['label'] : $this->elm_options['id'])); 667 | 668 | unset($this->elm_options['id']); 669 | unset($this->elm_options['label']); 670 | 671 | $class = str_replace($this->config['default_button_classes'], '', $this->elm_options['class']); 672 | $class = str_replace($this->config['bootstrap_required_input_class'], '', $class); /* remove the 'form-control' class */ 673 | /* add class="valid" to all dropdowns (makes them not full width - and works better with select2 plugin) */ 674 | if (strpos($class, $this->config['default_button_classes']) === FALSE) { 675 | $class .= ' ' . $this->config['default_button_classes']; 676 | } 677 | $this->elm_options['class'] = trim($class); 678 | 679 | $input_html_string = form_submit($name, $label, $this->_create_extra_string($this->elm_options)); 680 | break; 681 | case 'form_option': 682 | case 'form_dropdown': 683 | /* form_dropdown is different than an input */ 684 | if (isset($this->elm_options['options']) && !empty($this->elm_options['options'])) { 685 | $name = $this->elm_options['name']; 686 | $options = $this->elm_options['options']; 687 | $value = $this->elm_options['value']; 688 | 689 | unset($this->elm_options['name']); 690 | unset($this->elm_options['value']); 691 | unset($this->elm_options['options']); 692 | 693 | if (!empty($this->config['default_dropdown_class'])) { 694 | $class = str_replace($this->config['bootstrap_required_input_class'], '', $this->elm_options['class']); 695 | /* add class="valid" to all dropdowns (makes them not full width - and works better with select2 plugin) */ 696 | if (strpos($class, $this->config['default_dropdown_class']) === FALSE) { 697 | $class .= ' ' . $this->config['default_dropdown_class']; 698 | } 699 | 700 | if (strpos($class, $this->config['bootstrap_required_input_class']) === FALSE) { 701 | $class .= ' ' . $this->config['bootstrap_required_input_class']; 702 | } 703 | $this->elm_options['class'] = trim($class); 704 | } 705 | 706 | $input_html_string = form_dropdown($name, $options, $value, $this->_create_extra_string()); 707 | } else { 708 | dump($this->elm_options); 709 | show_error('Tried to create `form_dropdown` with no options. (id="' . $this->elm_options['name'] . '")'); 710 | } 711 | break; 712 | case 'form_html': 713 | if (!isset($this->elm_options['html'])) { 714 | dump($this->elm_options); 715 | show_error('Tried to create `form_html` with no html. (id="' . $this->elm_options['id'] . '")'); 716 | } 717 | $input_html_string = $this->elm_options['html']; 718 | break; 719 | case 'form_textarea': 720 | $this->elm_options['value'] = html_entity_decode($this->elm_options['value']); 721 | $input_html_string = form_textarea($this->elm_options); 722 | break; 723 | case 'form_file': 724 | $input_html_string = form_upload($this->elm_options); 725 | break; 726 | case 'form_checkbox': 727 | $input_html_string = form_checkbox($this->elm_options); 728 | break; 729 | case 'form_radio': 730 | $input_html_string = form_radio($this->elm_options); 731 | break; 732 | default: 733 | if (function_exists($this->func)) { 734 | $input_html_string = call_user_func($this->func, $this->elm_options); 735 | } else { 736 | show_error("Could not find function to build form element: '{$this->func}'"); 737 | } 738 | break; 739 | } 740 | } 741 | $ret_string = ''; 742 | $ret_string .= ($include_pre_post) ? $this->_pre_input() : ''; 743 | $ret_string .= $this->_build_input_addons_pre(); 744 | $ret_string .= (empty($input_html_string)) ? $this->config['empty_value_html'] : $input_html_string; 745 | $ret_string .= $this->_build_input_addons_post(); 746 | $ret_string .= ($include_pre_post) ? $this->_build_help_block() : ''; 747 | $ret_string .= ($include_pre_post) ? $this->_post_input() : ''; 748 | 749 | return $ret_string; 750 | } 751 | 752 | private function _build_input_addons_pre() { 753 | $ret_string = ''; 754 | if ($this->input_addons['exists']) { 755 | if (!empty($this->input_addons['pre_html'])) { 756 | $ret_string = $this->input_addons['pre_html']; 757 | } else { 758 | $ret_string .= '
'; 759 | foreach ($this->input_addons['pre'] as $pre_addon) { 760 | $ret_string .= '' . $pre_addon . ''; 761 | } 762 | } 763 | } 764 | return $ret_string; 765 | } 766 | 767 | private function _build_input_addons_post() { 768 | $ret_string = ''; 769 | if ($this->input_addons['exists']) { 770 | if (!empty($this->input_addons['post_html'])) { 771 | $ret_string = $this->input_addons['post_html']; 772 | } else { 773 | foreach ($this->input_addons['post'] as $post_addon) { 774 | $ret_string .= '' . $post_addon . ''; 775 | } 776 | } 777 | $ret_string .= '
'; 778 | } 779 | return $ret_string; 780 | } 781 | 782 | private function _create_extra_string() { 783 | $extra = ''; 784 | foreach ($this->elm_options as $k => $v) { 785 | $extra .= " {$k}=\"{$v}\""; 786 | } 787 | return trim($extra); 788 | } 789 | 790 | private function _build_form_open($action, $attributes) { 791 | return form_open_multipart($action, $attributes); 792 | } 793 | 794 | private function _pre_elm() { 795 | return '
'; 796 | } 797 | 798 | private function _post_elm() { 799 | return '
'; 800 | } 801 | 802 | private function _pre_input() { 803 | if (($this->func === 'form_date') && ($this->config['default_datepicker_class'] !== '')) { 804 | return '
'; 805 | } 806 | return '
'; 807 | } 808 | 809 | private function _build_help_block() { 810 | if (!empty($this->elm_options_help)) { 811 | return '' . $this->elm_options_help . ''; 812 | } 813 | return ''; 814 | } 815 | 816 | private function _post_input() { 817 | return '
'; 818 | } 819 | 820 | /** 821 | * Create a label 822 | * @param boolean $link_to_input_id If set to FALSE, the label won't be linked to an input (i.e. for radio button and checkboxes) 823 | * @return string 824 | */ 825 | private function _label($link_to_input_id = TRUE) { 826 | $label = ''; 827 | if (isset($this->elm_options['label']) && $this->elm_options['label'] == 'none') { 828 | return ''; /* the keyword none */ 829 | } else if (isset($this->elm_options['label'])) { 830 | $label = $this->elm_options['label']; 831 | } elseif (isset($this->elm_options['id']) && $this->func != 'form_submit') { 832 | $label = $this->_make_label($this->elm_options['id']); 833 | } 834 | 835 | if ($this->func == 'form_submit') { 836 | $label = ''; 837 | } 838 | 839 | return form_label($label, $link_to_input_id ? $this->elm_options['name'] : '', array( 840 | 'class' => $this->config['default_control_label_class'] 841 | )); 842 | } 843 | 844 | private function _make_label($str) { 845 | return ucwords(str_replace(array('_', '-', '[', ']'), array(' ', ' ', ' ', ' '), $str)); 846 | } 847 | 848 | private function _reset_builder() { 849 | $this->print_string = ''; 850 | $this->func = $this->config['default_input_type']; 851 | } 852 | 853 | private function _recursive_build_json($ary, $offset = 0) { 854 | $kv_str = ''; 855 | foreach ($ary as $k => $v) { 856 | /* This offset class doesn't look that great :/ ' */ 857 | $offset_class = ''; 858 | if ($offset >= 1) { 859 | $offset_class = 'col-sm-offset-' . $offset; 860 | } 861 | 862 | if ((is_array($v) || is_object($v)) && !is_string($v)) { 863 | $new_offset = $offset + 1; 864 | $innter_str = $this->_recursive_build_json((array) $v, $new_offset); 865 | $kv_str .= '
' . ucwords(strtolower(str_replace(array('_', '-'), ' ', $k))) . '' . $innter_str . '
'; 866 | } else { 867 | $kv_str .= '
' . ucwords(strtolower(str_replace(array('_', '-'), ' ', $k))) . ': ' . $v . '
'; 868 | } 869 | } 870 | return $kv_str; 871 | } 872 | 873 | /* 874 | =============================================================================================== 875 | Specific Input_* 876 | =============================================================================================== 877 | */ 878 | } 879 | --------------------------------------------------------------------------------