Using CodeIgniter, how do I access and display text entered into an input field on a view file (see code below) from my controll开发者_如何学Cer file?
// input_view.php
<?php
echo form_open('search/submit');
$input_data = array('name' => 'search_field', 'size' => '70');
echo form_input($input_data);
form_submit('submit','Submit');
form_close();
?>
When text is entered into an input field, it is impossible to access until the form has been posted back to the server. In other words, the form must be submit for your controller to see it.
Let's say you have a form in the file called input_view.php:
<?php echo form_open('my_controller/my_method'); ?>
<?php echo form_input('search'); ?>
<?php echo form_submit('submit', 'Search'); ?>
When this form is submit, it will be sent to the 'my_controller' controller.
Now, Here's what the my_method should look like if you want to simply print the contents of the search field:
public function my_method() {
if ($this->input->post()) {
$name = $this->input->post('search');
echo $name;
}
}
I hope this helps.
精彩评论