|
1 | 1 | CakePHP Bootstrap 3 FormHelper
|
2 | 2 | =============================
|
3 | 3 |
|
4 |
| -Version 1.0 |
| 4 | +Yet another Cake 2.x form helper, but with minimal coding and highly configurable. |
5 | 5 |
|
6 |
| -[](https://travis-ci.org/Codaxis/bootstrap3-helpers) |
| 6 | +Feel free to make any code/docs contributions or post any issues. |
7 | 7 |
|
8 |
| -Yet another Cake form helper, but with minimal coding and highly configurable. |
| 8 | +[](https://travis-ci.org/Codaxis/cakephp-bootstrap3-helpers) |
9 | 9 |
|
10 |
| -Compatible with Cake 2.4.6+ |
| 10 | +## Installation |
11 | 11 |
|
12 |
| -Feel free to make any code/docs contributions or post any issues. |
| 12 | +1. Install with composer by running `composer require codaxis/cakephp-bootstrap3-helpers:1.1` or clone/copy files into `app/Plugin/Bs3Helpers` |
| 13 | + |
| 14 | +2. Include the plugin in your bootstrap.php with `CakePlugin::load('Bs3Helpers')` or `CakePlugin::load('Bs3Helpers', array('bootstrap' => true))` to load included default Bootstrap form styles. |
| 15 | + |
| 16 | +3. Load helper in your ```AppController```. Use classname option if you want to keep your helper alias as Form. |
| 17 | + |
| 18 | + ```php |
| 19 | + // In AppController.php |
| 20 | + public $helpers = array('Bs3Helpers.Bs3FormHelper'); |
| 21 | + // or |
| 22 | + public $helpers = array('Form' => array('className' => 'Bs3Helpers.Bs3FormHelper')); |
| 23 | + ``` |
| 24 | + |
| 25 | +4. Define your custom form styles at wish in your bootstrap.php |
| 26 | + |
| 27 | + |
| 28 | +## Form helper usage options |
| 29 | + |
| 30 | +**BsFormHelper::create() custom options:** |
| 31 | + |
| 32 | +- ```formStyle``` => shortcut for custom form styles. E.g.: ```formStyle => inline``` will add 'form-inline' class to form tag |
| 33 | + |
| 34 | +- ```submitDiv``` => if set, will enable end() method div option and set passed div class. Useful to be used gloabally or with a defined form style |
| 35 | + |
| 36 | +**Bs3FormHelper::input() default base options:** |
| 37 | + |
| 38 | +- ```class``` => ```'form-control'``` |
| 39 | +- ```div``` => ```array('class' => 'form-group')``` |
| 40 | +- ```label``` => ```array('class' => 'control-label')``` |
| 41 | +- ```error``` => ```array('attributtes' => 'array('class' => 'help-block'))``` |
| 42 | + |
| 43 | + |
| 44 | +**Bs3FormHelper::input() custom options:** |
| 45 | + |
| 46 | +- ```beforeInput``` => html code to prepend right before the input. |
| 47 | +- ```afterInput``` => html code to append right after the input. |
| 48 | +- ```wrap``` => if set, will wrap the form input inside a div with the css class passed. |
| 49 | +Useful for input sizing. |
| 50 | +- ```help``` => help text to show after input. Will be rendered inside a div with .help-block class. |
| 51 | +- ```errorClass``` => Error class for .form-group div. Defaults to 'has-error'. |
| 52 | +- ```errorsAlwaysAsList``` => if set to true, will render error messages always inside as list, no matter if there's only one error. Useful to ensure ui consistency. |
| 53 | +- ```feedback``` => allows feedback icons in text inputs, passing ```fa-icon-name``` or ```glyphicon-icon-name``` will render the full ```<i>``` tag. |
| 54 | +- ```inputGroup``` => array options that supports the following params: |
| 55 | + - ```size``` => can be ```sm``` or ```lg``` |
| 56 | + - ```prepend```: html code to prepend. If it starts with ```fa``` or ```glyphicon```, will be interpreted as an icon and the full icon tag will be rendered. |
| 57 | + - ```append```: html code to prepend. If it starts with ```fa``` or ```glyphicon```, will be interpreted as an icon and the full icon tag will be rendered. |
| 58 | +- ```externalWrap``` => if set, the whole input div (without taking into account .help-block) will be wrapped inside another div with the given class will be applied, preventing unnecessary shrinking in some cases. Solves this issue https://github.com/twbs/bootstrap/issues/9694. |
| 59 | +- ```checkboxLabel```: if set, will wrap a single checkbox inside a ```div.checkbox``` and a ```label``` with the passed text. |
| 60 | +- ```inline``` => used in conjuntion with checkbox and radio groups to allow inline display. |
| 61 | + |
| 62 | + |
| 63 | +## Global form styles |
| 64 | + |
| 65 | +Global form styles can be defined in bootstrap.php and used anywhere by passing the ```formStyle``` option in create() method. |
| 66 | + |
| 67 | +Inbuilt styles horizontal and inline included are defined like: |
13 | 68 |
|
14 |
| ---- |
15 |
| -#### Version 1.1 in progress, will be released soon |
16 |
| ---- |
| 69 | +```php |
| 70 | +Configure::write('Bs3.Form.styles', array( |
| 71 | + 'horizontal' => array( |
| 72 | + 'formDefaults' => array( |
| 73 | + 'submitDiv' => 'col-sm-10 col-sm-offset-2' |
| 74 | + ), |
| 75 | + 'inputDefaults' => array( |
| 76 | + 'label' => array( |
| 77 | + 'class' => 'col-sm-2 control-label' |
| 78 | + ), |
| 79 | + 'wrap' => 'col-sm-10', |
| 80 | + ) |
| 81 | + ), |
| 82 | + 'inline' => array( |
| 83 | + 'inputDefaults' => array( |
| 84 | + 'label' => array( |
| 85 | + 'class' => 'sr-only' |
| 86 | + ), |
| 87 | + ) |
| 88 | + ) |
| 89 | +)); |
| 90 | +``` |
17 | 91 |
|
18 |
| -## How to use |
| 92 | +## Html helper usage options |
19 | 93 |
|
20 |
| -Usage instructions and extensive examples can be found at http://bs3form.codaxis.com |
| 94 | +TODO |
21 | 95 |
|
22 | 96 | ## License
|
23 | 97 |
|
|
0 commit comments