问题
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