Using Codeigniter, how do I get and display, from my controller, all of the text a user entered into a text field on a view? I only get the first word, and nothing after the spaces.
Here are my form_validation rules
$this->form_validation->set_rules(
'f开发者_Go百科ield_name','Field Name','trim|required|alpha_numeric|tolower|xss_clean');
And here is my controller
public function my_method() {
if ($this->input->post()) {
$name = $this->input->post('search');
echo $name;
}
}
and my view
?php echo form_open('my_controller/my_method'); ?>
<?php echo form_input('search'); ?>
<?php echo form_submit('submit', 'Search'); ?>
Because, you specified alpha_numeric. A space character is not an alphabetic character, nor is it a number, so it's truncating the string.
Hmm.. try taking out 'trim'?
$this->form_validation->set_rules( 'field_name','Field Name','required|alpha_numeric|tolower|xss_clean');
If not, try removing xss_clean.
You don't need to specify a rule "that would allow spaces". You should always, however, specify a maximum length for character input fields.
max_length[255]
精彩评论