Using CakePHP FormHelper with Bootstrap Forms

前端 未结 9 625
天命终不由人
天命终不由人 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:17

    Inspired by lericson's answer, this is my final solution for CakePHP 2.x:

    Form->create('ModelName', array(
        'class' => 'form-horizontal',
        'inputDefaults' => array(
            'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
            'div' => array('class' => 'control-group'),
            'label' => array('class' => 'control-label'),
            'between' => '
    ', 'after' => '
    ', 'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')), )));?>
    Form->input('Fieldname', array( 'label' => array('class' => 'control-label'), // the preset in Form->create() doesn't work for me )); ?>
    Form->end();?>

    Which produces:

    
    
    Error message

    I basically added the 'format' and 'error' keys, and added the control-label class to the label element.

提交回复
热议问题