In this article, we will discuss how to get and post data from a controller in CodeIgniter and provide some examples of how to use the GET and POST methods to get and post data from a controller.
Following are 2 simple ways to get input data from a form in CodeIgniter.
Table of Contents
Form
<?php echo form_open(''); ?> <div class="form-group"> <textarea class="form-control" name="text" placeholder="Your text..." rows="10"></textarea> </div> <div class="form-group"> <input type="checkbox" name="trim"> Trim text? </div> <div class="form-group text-center"> <input type="submit" name="submit" class="btn btn-primary" value="Submit"> </div> <?php echo form_close(); ?>
Query GET Data
$text = $this->input->get('name'); $isTrim = $this->input->get('trim'); $text = $_GET['name']; $isTrim = $_GET['trim'];
Query POST Data
$text = $this->input->post('name'); $isTrim = $this->input->post('trim'); $text = $_POST['name']; $isTrim = $_POST['trim'];