php Cakephp 文本区域
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12799689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cakephp textarea
提问by Jo?o Gon?alves
I am using CakePHP 2.2.3. I have a contact form with a model without a table but with validation rules.
我正在使用 CakePHP 2.2.3。我有一个联系表单,其中包含一个没有表格但带有验证规则的模型。
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.
我的问题是,如何告诉 CakePHP 输入类型是 textarea ?我可以使用,$this->Form->textarea()但我注意到当我使用它时,它不会创建正确的 HTML 来报告验证错误。如果我使用$this->Form->input()它只是创建一个普通的输入类型文本。
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.
注意没有<div class="input email required"></div>,我假设它是 CakePHP 用来注入验证错误的 DOM 元素。
I would like to know what's the best way to achieve this.
我想知道实现这一目标的最佳方法是什么。
回答by 472084
I tend to use input() for all types and then specify in the options array..
我倾向于对所有类型使用 input() ,然后在选项数组中指定..
$this->Form->input('company_description', array('type' => 'textarea'));
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
回答by scx
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
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#automagic-form-elements
回答by Kuldeep Tiwari
<?= $this->Form->input('comment', ['type' => 'textarea', 'label' => false, 'placeholder'=> 'Comment here', 'escape' => false,'class' =>'comment', 'rows' => '10', 'cols' => '20']); ?>
Creates a textareawith specified number of rows and cols, not just a standard textarea.
创建textarea具有指定行数和列数的 ,而不仅仅是标准文本区域。

