0

Every time I create an input field using

$this->Form->input('name');

It creates a div element

<div class="input name">
  <input type="text">
</div>

Is there a way to prevent creation of div block around input field. Also, is there a way to add custom class to the div created? like

<div class="input name myStyle">
  <input>
</div>

I'm using CakePHP 3.2

Anuj TBE
  • 9,198
  • 27
  • 136
  • 285

2 Answers2

2

You need to override the templates. You can do this by creating a new config file:

config/app_form.php

return [
    'inputContainer' => '{{content}}'
];

Then load it in your View:

src/View/AppView.php

class AppView extends View
{
    public function initialize()
    {
        parent::initialize();

        $this->loadHelper('Form', ['templates' => 'app_form']);
    }
}

http://book.cakephp.org/3.0/en/views/helpers/form.html#customizing-the-templates-formhelper-uses

BadHorsie
  • 14,135
  • 30
  • 117
  • 191
  • I want this in element. Adding this in view will effect all forms throughout the application ?. I want this only on one input field – Anuj TBE Jul 19 '16 at 12:45
  • @anujsharma9196 then you can do `$this->Form->input('name', [ 'templates' => [ 'inputContainer' => '{{content}}' ] ]);` – arilia Jul 19 '16 at 13:03
0
php echo $this->Form->create($user, ['type' => 'file', 'id'=>"change-profile-form",'role' => 'form','class'=>'orb-form']);

$this->Form->templates(['inputContainer' => '{{content}}']);


echo $this->Form->input('first_name', ['label'=>false, 'div'=>false, 'placeholder' => 'First name']);

I hope this would be help you.

Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42