2

Following http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html. I am able to give class to every form field using inputDefaults but now:

Required: I want to append the class (say myClass) in some particular input to those that are inherited by inputDefaults.

'inputDefaults' => array(
     'label' => false,
     'div' => 'form-group',
     'class' => 'col-sm-6 form-control'
 )

Every Input Field

<input type="email" id="LoginEmail" maxlength="100" required="required" placeholder="Email" class="col-sm-6 form-control" name="data[Login][email]" />

If I Try:

echo $this->Form->input("email", array("placeholder" => "Email", "required" => "required", "class" => "myClass"));

I get

 <input type="email" id="LoginEmail" maxlength="100" required="required" placeholder="Email" class="myClass" name="data[Login][email]" />

I want as Follows

 <input type="email" id="LoginEmail" maxlength="100" required="required" placeholder="Email" class="col-sm-6 form-control myClass" name="data[Login][email]" />

Thanks in Advance!

Ashwani Goyal
  • 616
  • 4
  • 18

1 Answers1

1

As you are trying to use twitter bootstrap with cakephp, you may find already coded form helper from https://github.com/Codaxis/cakephp-bootstrap3-helpers#installation handy

Just alias the Bs3Helpers.Bs3Form one to the std Form as shown there in the installation section and configure the helper in the bootstrap.php.

Another tip is a bake script template: https://github.com/ptica/BootstrapCake

ptica
  • 749
  • 8
  • 16
  • I appreciate your help @ptica but I am not making new project but working on existing project i.e. so very complex. – Ashwani Goyal Apr 21 '15 at 17:26
  • than @sgt is right: 1) code own helper (as https://github.com/Codaxis/cakephp-bootstrap3-helpers/blob/master/View/Helper/Bs3FormHelper.php#L20) with overloaded `input` method 2) alias it as the Form as shown in the installation link above – ptica Apr 21 '15 at 17:54