How do I set a maxlength for Codeigniters form_textarea()?

元气小坏坏 提交于 2019-12-12 00:57:59

问题


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>

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.

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


回答1:


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

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

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

form_textarea()

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".

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
);



回答2:


form_textarea(array(
    'cols' => 1, 
    'rows' => 1
));


来源:https://stackoverflow.com/questions/16808969/how-do-i-set-a-maxlength-for-codeigniters-form-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!