Sticky form elements in CodeIgniter

It is good for user experience to offer feedback; we do this in the preceding sections with validation_errors(), but it is also useful to keep user data in form elements to save them having to re-type everything, should there be an error. To do this, we need to use CodeIgniter's set_value() function.

Getting ready

Make sure that you load $this->load->helper('form'); from within the __constructor() of the controller; however, you can always autoload the helper from /

How to do it...

We're going to edit the /path/to/codeigniter/application/views/new_record.php file.

  1. Amend the file to show the following (changes in bold):
    <?php echo form_open('form/submit_form') ; ?> ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.