PHP Classes

Codeigniter Db_form: Generate forms to edit database table records

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 285 All time: 7,538 This week: 139Up
Version License PHP version Categories
ci-db-form-generator 1.7Artistic License5.3HTML, PHP 5, Databases
Description 

Author

This class can generate forms to edit database table records using Code Igniter.

It can setup a form given a table name and optional table fields to be edited in the form.

The class can configure properties of the fields to include like the type, options, content, attributes.

The form fields can be loaded from the results of a given database query.

The class can render the form output from the given form and field definitions.

Picture of Ulisses Mantovani
Name: Ulisses Mantovani <contact>
Classes: 2 packages by
Country: Brazil Brazil
Age: 35
All time rank: 3042219 in Brazil Brazil
Week rank: 91 Up6 in Brazil Brazil Up

Example

<?php

$this
->load->library('db_form', array(), 'form');

/* Instance form (required)*/
// 1 mode
$this->form->setForm('<table name>');
// 2 mode
$this->form->setForm('<table name>', array('<field name>'=>'<label name>', ...) );

/* configuring render (optional)*/
// Filter fields
$this->form->setForm('<table name>')->filter( array('<field name>', ... ) );

// Change field parameters | Change/Add Label text
$this->form->field('<field name>')->label('<label text>');

// Change field parameters | Change type (form library codeigniter)
$this->form->field('<field name>')->type('dropdown');

// Change field parameters | add options to field (for dropdown, radio, checkbox, etc)
$this->form->field('<field name>')->options( array('< value >'=>'< label >', ...) );

// Change field parameters | add html attributes
$this->form->field('<field name>')->attr( array('< attribute >'=>'< value >', ...) );

// Change field parameters | add value or array values for checkbox
$this->form->field('<field name>')->value( '<field value>' );

// Change field parameters | set new values for class parameter to unique field
$this->form->field('<field name>')->config( array('<class variable>'=>'<new value>') );

// Change field parameters | add pre and after input content
$this->form->field('<field name>')->content( array('before'=>'< value >', 'after'=>'< value >') );

/* Configuring general bootstrap render output */
// Dynamic Change class parameters
$this->form->setConfig( array('<config var>'=>'<new value>') );

// Stand alone change
$this->form-><config var> = '<new value>';

/* IMPORTANT: see config vars in end of this Doc */

/* Fill form with result (optional)*/
// Get query
$qr = $this->db->query( '<row return>' )->result_array();
// or Set array
$qr = array( '<field name1>'=>'<value>', ... );

$this->form->fill( $qr );

/* Render form (required )*/
// For default print a array with block input | optional parameter print(true|false)
$rtn = $this->form->render( <auto print(true|false)> );

echo
$rtn['<field name>'];


/* Public config vars */
/*
 $fieldset = true;
 $fieldset_name = '';
 $out_type = 'bootstrap';
 $form_class = 'form-horizontal';
 $form_action = '';
 $parentt = true;
 $parent_tag = 'div';
 $parent_class = 'form-group';
 $label = true;
 $label_tag = 'label';
 $label_class = 'col-md-3 control-label';
 $input_parent = true;
 $input_parent_tag = 'div';
 $input_parent_class = 'col-md-6';
 $input_class = 'form-control';
 $input_check = array('checkbox'=>'');
 $btn_submit = true;
 $btn_submit_config = array('name'=>'btn_submit', 'class'=>'btn btn-success', 'value'=>'Gravar');
 $btn_apply = true;
 $btn_apply_config = array('name'=>'btn_apply', 'class'=>'btn btn-info', 'value'=>'Aplicar');
 $submit_config = array('label_tag'=>'div');
*/
?>


Screenshots  
  • 2tr.png
  • 1tr.png
  Files folder image Files  
File Role Description
Plain text file Db_class.php Class Class to instance
Accessible without login Plain text file examples.php Example Examples of implementation

 Version Control Unique User Downloads Download Rankings  
 0%
Total:285
This week:0
All time:7,538
This week:139Up