如何为Codeigniters form_textarea()设置最大长度? [英] How do I set a maxlength for Codeigniters form_textarea()?

查看:122
本文介绍了如何为Codeigniters form_textarea()设置最大长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为Codeigniter中的 form_textarea()设置一个 maxlength

I am trying to set a maxlength for the form_textarea() in Codeigniter.

我尝试了以下方法:

I tried the following:

<?php

$options = array(
    'maxlength' => '100'
    );

?>

<tr>
<td><?= form_label('Profiel:');?></td>
<td><?= form_textarea('Profiel', $options,  $info['Profiel']);?></td>
</tr>

当我编辑我的表单来编辑textarea中的文本时,它说Array。所以文本不见了,并且被数组取代。

When I edit my form to edit the text in the textarea it says Array. So the text is gone and is replaced with Array.

但那不起作用。
也许我必须使用Jquery?

But that is not working. Maybe I have to use Jquery?

推荐答案

Codeigniter允许您通过关联数组

Codeigniter allows you to pass attributes into your form elements by way of an associative array.

表单助手的文档在这里: http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html

Documentation for the form helper is here: http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html

尽管我可以准确地看到你试图做的事情,有一个与textareas警告。从文档:

Although I can see exactly what you're trying to do, there's one caveat with textareas. From the documentation:


form_textarea()

这个函数在所有方面都与上面的form_input()
函数相同,除了它生成一个textarea类型。注意:
而不是上面例子中的maxlength和size属性,而是
,您将改为指定rows和cols。

This function is identical in all respects to the form_input() function above except that it generates a "textarea" type. Note: Instead of the "maxlength" and "size" attributes in the above example, you will instead specify "rows" and "cols".

所以,你需要传递行和列而不是maxtaxttata。你的代码看起来像这样:

So, you need to pass rows and columns instead of maxlength for textareas. Your code would look something like this:

$options = array(
    'rows' => 10,
    'cols' => 10
);

这篇关于如何为Codeigniters form_textarea()设置最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆