I\'m using Bootstrap 3.0RC1
with CakePHP 2.3.6
. Trying to take advantage of those beautiful looking classes like has-error
and has-w
If you introspect FormHelper
, you'll find in this line "ugly" code that do error magic.
Since original authors did not leave any chance to do this by configuration, I'm suggesting you writing own BootstrapFormHelper
, and override input function, by changing that single line.
Here is snippet:
//inside public function input($fieldName, $options = array())
$out['error'] = null;
if ($type !== 'hidden' && $error !== false) {
$errMsg = $this->error($fieldName, $error);
if ($errMsg) {
$divOptions = $this->addClass($divOptions, 'has-error'); //old string value was 'error'
if ($errorMessage) {
$out['error'] = $errMsg;
}
}
}
Since I'm already using custom BootstrapFormHelper
, here is link to full gist.
Just copy file to app\View\Helper
, and add to ALL your Controllers this line:
public $helpers = array(
'Form' => array('className' => 'BootstrapForm')
);
assuming that you've saved gist as BootstrapFormHelper.php
.