-
Notifications
You must be signed in to change notification settings - Fork 0
Form to Table
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] function addPage() { $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', $data); } [/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();
}
[/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] |