Anthony
Anthony

Reputation: 4050

Form Input Gets 1 Word

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

Upvotes: 0

Views: 81

Answers (3)

coolgeek
coolgeek

Reputation: 923

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]

Upvotes: 1

Lotus Notes
Lotus Notes

Reputation: 6363

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

Upvotes: 2

Tim
Tim

Reputation: 7056

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.

Upvotes: 1

Related Questions