Skip to content

Instantly share code, notes, and snippets.

@Suven
Last active July 3, 2018 00:12
Show Gist options
  • Select an option

  • Save Suven/6325905 to your computer and use it in GitHub Desktop.

Select an option

Save Suven/6325905 to your computer and use it in GitHub Desktop.

Revisions

  1. Suven revised this gist Aug 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion BootstrapFormHelper.php
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@
    * )
    * );
    *
    * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
    * @link https://gist.github.com/Suven/6325905
    */
    class BootstrapFormHelper extends FormHelper {

  2. Suven created this gist Aug 24, 2013.
    64 changes: 64 additions & 0 deletions BootstrapFormHelper.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <?php
    App::uses('FormHelper', 'View/Helper');

    /**
    * BootstrapFormHelper.
    *
    * Applies styling-rules for Bootstrap 3
    *
    * To use it, just save this file in /app/View/Helper/BootstrapFormHelper.php
    * and add the following code to your AppController:
    * public $helpers = array(
    * 'Form' => array(
    * 'className' => 'BootstrapForm'
    * )
    * );
    *
    * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
    */
    class BootstrapFormHelper extends FormHelper {

    public function create($model = null, $options = array()) {
    $defaultOptions = array(
    'inputDefaults' => array(
    'div' => array(
    'class' => 'form-group'
    ),
    'label' => array(
    'class' => 'col-lg-2 control-label'
    ),
    'between' => '<div class="col-lg-10">',
    'seperator' => '</div>',
    'after' => '</div>',
    'class' => 'form-control',
    ),
    'class' => 'form-horizontal',
    'role' => 'form',
    );

    if(!empty($options['inputDefaults'])) {
    $options = array_merge($defaultOptions['inputDefaults'], $options['inputDefaults']);
    } else {
    $options = array_merge($defaultOptions, $options);
    }
    return parent::create($model, $options);
    }

    // Remove this function to show the fieldset & language again
    public function inputs($fields = null, $blacklist = null, $options = array()) {
    $options = array_merge(array('fieldset' => false), $options);
    return parent::inputs($fields, $blacklist, $options);
    }

    public function submit($caption = null, $options = array()) {
    $defaultOptions = array(
    'class' => 'btn btn-primary',
    'div' => 'form-group',
    'before' => '<div class="col-lg-offset-2 col-lg-10">',
    'after' => '</div>',
    );
    $options = array_merge($defaultOptions, $options);
    return parent::submit($caption, $options);
    }

    }