nbhatti2001
nbhatti2001

Reputation: 363

Cakephp 3 form input div in div

I recently start a new project using cakephp 3. I have to generate a particular form for input box, as I am using AdminLTE V2. Admin LTE required HTML is as following

<div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Email</label>

    <div class="col-sm-10">
        <input class="form-control" id="inputEmail3" placeholder="Email" type="email">
    </div>
</div>

I have generate it as following

<div class="form-group input text required">
    <label class="col-sm-3 control-label" for="full-name">Full Name</label>
    <input type="text" name="full_name" class="form-control" required="required" maxlength="100" id="full-name">
</div>

I need to generate the inner <div>. How I can do this? Please help.

Upvotes: 0

Views: 1584

Answers (3)

Dakota
Dakota

Reputation: 458

Use the friends of cake bootstrap plugin available at https://github.com/friendsofcake/bootstrap-ui

It already includes full support for bootstrap based themes.

Upvotes: 0

Prakash Saini
Prakash Saini

Reputation: 481

For this CakePhp provide Customizing the Templates FormHelper. Like many helpers in CakePHP, FormHelper uses string templates to format the HTML it creates. While the default templates are intended to be a reasonable set of defaults. You may need to customize the templates to suit your application.

Below i have customize the input field according to AdminLTE.

echo $this->Form->input('email', [
'label' => ['text' => 'Email','class' => 'col-sm-2'],
'templates' => [
'label' => '<label{{attrs}}>{{text}}</label>',
'input' => '<div class="col-sm-10"><input type="{{type}}" name="{{name}}"  {{attrs}}/></div>',
'inputContainer' => '<div class="form-group {{type}}{{required}}">{{content}}</div>',
'inputContainerError' => '<div class="form-group  {{type}}{{required}} has-error">{{content}}{{error}}</div>',
],
]);

The output of this in AdminLTE theme is following.

<div class="form-group text">
<label class="col-sm-2" for="email">Email</label>
   <div class="col-sm-10">
      <input type="text" name="email" placeholder="Email" id="first-name">
   </div>
</div>

Upvotes: 4

Bruno Lamps
Bruno Lamps

Reputation: 646

You can just use plain html, as @Manohar said. But if you really prefer cakephp's syntax, I use this type of syntax in my projects (same theme):

<div class="form-group">
 <?php echo $this->Form->label('descricao', 'Descrição'); ?>
 <div class="col-sm-10">
  <?php echo $this->Form->input('descricao', ['label' => false, 'class' => 'form-control', 'placeholder' => "myPlaceHolder"]); ?>
 </div>
</div>

You might need some additional parameters to do exactly what is written in the pure html version of your code. You can check out other options for cakephp's forms in it's documentation: http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-form-inputs

Upvotes: -1

Related Questions