Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form checkbox and label with CakePHP and Bootstrap

I'm having some issues trying to get checkbox inputs and labels to output the correct HTML using CakePHP and Twitter Bootstrap.

The Bootstrap specific output should be:

<div class="control-group">
  <div class="controls">
    <label class="checkbox">
      <input type="checkbox"> Keep me logged in
    </label>
  </div>
</div>

However, using the inputDefaults mentioned here (http://stackoverflow.com/a/9496242/1247225), this Cake form input:

echo $form->input('auto_login', array(
 'type' => 'checkbox', 
 'label' => __('Keep me logged in', true)));

Outputs this:

  <div class="control-group">
    <input type="hidden" name="data[User][auto_login]" id="UserAutoLogin_" value="0" />
    <input type="checkbox" name="data[User][auto_login]" class="" value="1" id="UserAutoLogin" />
    <div class="controls">
      <label for="UserAutoLogin">Keep me logged in</label>
    </div>
  </div>

Any ideas how to adjust this individual input so it outputs the correct Bootstrap HTML, like above?

like image 438
gman88 Avatar asked Nov 30 '22 06:11

gman88


1 Answers

The best way to control the form output, or the format of the output, is by passing a 'format' argument. Try playing with this:

'format' => array('before', 'label', 'input', 'between', 'after', 'error')

I don't think it is document, but by reading the code, you can find it in there.

like image 167
Jeremiah Crouch Avatar answered Dec 03 '22 23:12

Jeremiah Crouch