Reputation: 4002
I am using CakePHP 2.2.3. I have a contact form with a model without a table but with validation rules.
My problem is, how to tell CakePHP that the input type is textarea ? I could use $this->Form->textarea()
but I've noticed that when I use it, it doesn't create the proper HTML to report validation errors back. If I use $this->Form->input()
it just creates a normal input type text.
It should create something like:
<div class="input email required"><input name="data[Quote][email]" required="1" type="email" id="QuoteEmail"/></div>
but instead it creates something like:
<textarea name="data[Quote][company_description]" id="QuoteCompanyDescription"></textarea>
notice the absence of <div class="input email required"></div>
, which I assume is the DOM element CakePHP uses to inject the validation error.
I would like to know what's the best way to achieve this.
Upvotes: 6
Views: 26253
Reputation: 11
<?= $this->Form->input('comment', ['type' => 'textarea', 'label' => false, 'placeholder'=> 'Comment here', 'escape' => false,'class' =>'comment', 'rows' => '10', 'cols' => '20']); ?>
Creates a textarea
with specified number of rows and cols, not just a standard textarea.
Upvotes: 0
Reputation: 2789
Try following which also include class that you specified as an option
echo $this->Form->input('company_description', array('type' => 'textarea', 'escape' => false,'class' =>'input email required');
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#automagic-form-elements
Upvotes: 3
Reputation: 17885
I tend to use input() for all types and then specify in the options array..
$this->Form->input('company_description', array('type' => 'textarea'));
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
Upvotes: 32