Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 35 revisions

Category:Helper Category:Form Category:Table

How about not having to create any tables around forms anymore?

This will create the form and the table: [code] $data = form_open('admin/addPage', $attributes); $form['Title'] = '<input type="text" name="Title" value="" maxlength="200" size="50" />'; $form[1]['slug'] = '<input type="text" name="slug" />'; $form[1]['Group'] = form_dropdown('groups', user_groups(), 'User'); $form['Body'] = '<textarea name="Body" rows="20" cols="80" /></textarea>'; $form[''] = '<input type="submit" name="submit_page" value="Submit" />'; $data .= form_table($form); $data .= '</form>'; $this->load->view('layout/blank', $this->tpl); [/code]

Just save this in a helper file: [code] function form_table($form) { $return = '

'; $this->load->library('table'); $this->table->set_template(table_form()); foreach($form as $k=>$v){ if(is_numeric($k)){ $head = array_keys($v); $this->table->set_heading($head); $return .= $this->table->generate($v); }else{ $this->table->set_heading($k); $this->table->add_row($v); $return .= $this->table->generate(); }
        $this->table->clear();
    }
    $return .= '</td></tr></table>';
    return $return;
}

[/code]

If you need help or even better have improvements let me know, please. I watch this thread: [url=http://codeigniter.com/forums/viewthread/48152/]Forum[/url]

Clone this wiki locally