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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

I want this in element. Adding this in view will effect all forms throughout the application ?. I want this only on one input field
@anujsharma9196 then you can do $this->Form->input('name', [ 'templates' => [ 'inputContainer' => '{{content}}' ] ]);
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.