How to Get Form GET and POST Data in CodeIgniter’s Controller

Following are 2 simple ways to get input data from a form in CodeIgniter.

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

GET

$text = $this->input->get('name');
$isTrim = $this->input->get('trim');

$text = $_GET['name'];
$isTrim = $_GET['trim'];

POST

$text = $this->input->post('name');
$isTrim = $this->input->post('trim');

$text = $_POST['name'];
$isTrim = $_POST['trim'];

Leave a Comment

Your email address will not be published. Required fields are marked *

We care about your privacy and data security. Google serves cookies to analyse traffic and show ads on this site. By using this site you agree to these cookies being set. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close