PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] How can I create cakephp 3 custom template

 February 17, 2022     cakephp, cakephp-3.0     No comments   

Issue

I am new in cakephp 3.

I want to create form helper that will generate code like this.

 <div class="form-group">
        <label for="inputEmail3" class="col-sm-3 control-label">Email</label>
        <div class="col-sm-9">
            <input type="email" class="form-control" id="inputEmail3" placeholder="Email" required="">
        </div>
</div>

I am using this

<?php 
        $myTemplates = [
            'inputContainer' => '<div class="form-group">{{label}}<div class="col-sm-9">{{input}}</div></div>',
            'inputContainerError' => '<div class="input {{class}} {{type}}{{required}} error">{{content}}{{error}}</div>'
        ];
    ?>
    <?= $this->Form->create('Users',['templates' => $myTemplates]) ?>                       
    <?= $this->Form->input('email',['class' => 'form-control','templates' => ['formGroup' => '{{input}}{{label}}']]) ?>

But it will generate wrong


Solution

First of all create Template code

<?php $myTemplates = [
'label' => '<label class="col-sm-3 col-form-label">{{text}}</label>',
'select' => '<div class="col-sm-9"><select class="form-control" name="{{name}}"{{attrs}}>{{content}}</select></div>',
'input' => '<div class="col-sm-9"><input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}></div>',
'inputContainer' => '<div class="form-control">{{content}}</div>',
'inputSubmit' => '<input type="{{type}}"{{attrs}}>',
'inputContainer' => '<div class="form-group row">{{content}}</div>',
'submitContainer' => '<div class="form-group row"><label class="col-sm-3 col-form-label">&nbsp;</label><div class="col-sm-9 ">{{content}}</div></div>',
]; ?>

Now Use this template code inside in form

<?php echo $this->Form->create($schoolAccount); ?>  
<?php $this->Form->setTemplates($myTemplates); ?>
<?php echo $this->Form->control('account_holder',['label'=>'Name of Account Holder']); ?>
<?php echo $this->Form->end(); ?>


Answered By - Sudhir
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing