phphtmlcodeigniterhelperform-fields

CodeIgniter's HTML Table Class with Form Helper


Is it possible to use Form Helper "inside" HTML Table Class in CodeIgniter?

This is what I mean:

$this->load->library('table');
$this->load->helper('form');
form_open('example/function')

$data = array(
             array(form_checkbox('newsletter', 'accept', TRUE), form_checkbox('newsletter', 'accept', TRUE),),
             );

echo $this->table->generate($data);

Solution

  • Of course this is possible, the form helper return only string so you can do something like that :

    <?php
    
    class Welcome extends CI_Controller {
        public function index()
        {
            $this->load->library('table');
            $this->load->helper('form');
    
            $data = array(
                array('Label', 'Input'),
                array('Name', form_input('name')),
                array('Firstname', form_input('firstname'))
            );
    
            echo $this->table->generate($data);
        }
    }