views:

28

answers:

3

Hi

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(
'field_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'); ?>
+1  A: 

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.

Tim
+1 Thanks for your reply. That was the first thing I did but it did not work
01010011
xss_clean? Isn't that important for preventing cross site scripting stuff?
01010011
+2  A: 

Because, you specified alpha_numeric. A space character is not an alphabetic character, nor is it a number, so it's truncating the string.

Lotus Notes
+1 Thanks for the reply. Oh yeah that was obvious. Hmmm. Is there a CI rule I could put in that would allow spaces?
01010011
+1  A: 

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]
coolgeek
+1 Thanks for this tip, thats true, I'll put it in.
01010011