Using CakePHP FormHelper with Bootstrap Forms

前端 未结 9 620
天命终不由人
天命终不由人 2020-12-12 14:56

CakePHP\'s FormHelper is how you generate forms when making CakePHP applications. As one might assume, this includes generating input elements, like so:

$thi         


        
9条回答
  •  被撕碎了的回忆
    2020-12-12 15:19

    Your answer is correct, but for the benefit of other users there's some other tweaks you can do to take advantage of the error/help text:

    Add form-horizontal to class in the Form->create() for more compact forms (labels on the left of the input, rather than on top)

    Here's how to put help text underneath a field (has to be done for each field), not forgetting to close the

    .

    echo $this->Form->input('field_name', array(
                'after'=>'This text appears 
                   underneath the input.
'));

and to correctly display errors:

// cake 2.0
echo $this->Form->input('abc', array(
    'error' => array('attributes' => array('class' => 'controls help-block'))
));

Outputs:

This is the error validation message.

It's extra mark-up and not as neat as bootstrap but it's a quick fix. The alternative is to do each error message individually.

and it lines up nicely. I haven't discovered an easy way to make use of inline messages yet however.

提交回复
热议问题