Giter Club home page Giter Club logo

db-form-bootstrap's Introduction

DB-Form-Bootstrap

PHP class that generate form fields and render with bootstrap tags (optionally).

Basic use

/* Include and Instance form (required)*/ 
include "Db_form2.php";
$form = new Db_form;
// array/object "field name" => "Label text"
$form->create( array('name'=>'Name', 'email'=>'Email') ); 
$form->render();

Configuring field render (optional)

//create and filter form
$form->create( array('name'=>'Name', 'email'=>'Email') )->filter( ['email'] ); 

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

// Change field parameters | Change type 
// (text(default)|hidden|password|upload|dropdown|checkbox|radio|button|textarea|empty) 
$form->field('name')->type('dropdown'); 

// Change field parameters | add options to field (for dropdown, radio, checkbox, etc) (Array/Object)
$form->field('name')->type('dropdown')->options( array( 1=>'Robert', 2=>'susan', ...) ); 

// Change field parameters | add html attributes 
$>form->field('name')->attr( array('id'=>'names', ...) ); 

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

// Change field parameters | set new values for class parameter to unique field 
/* IMPORTANT: see config vars in end of this Doc */ 
$form->field('name')->config( array('parent_class'=>'col-md-12') ); 

// Change field parameters | add before and after input content 
$form->field('name')->content( array('before'=>'i will appear above input', 'after'=>'i will appear below input') ); 

// Change field parameters | set a different sort number to field.
$form->field('name')->sort(3);

// Insert empty item
$form->field('validation')->type('empty')->value('This text appers on input spot');

Configuring global bootstrap render output vars /* IMPORTANT: see config vars in end of this Doc */

// Dynamic Change class parameters 
$form->setConfig( array('fieldset'=>false) ); 

// Stand alone change 
$form->fieldset = false; 

Fill form with result (optional)

// Get query array/object (Codeigniter example)
$qr = $this->db->query( 'SQL' )->result_array(); 
// or Set array 
$qr = array( 'name'=>'bob', 'email'=>'...' ); 

// Fill all fields
$form->fill( $qr ); 

Other render forms

// return all fields in array | optional parameter print(true|false) 
$rtn = $form->render(  ); 
echo $rtn['']; 

// render unique field
$form->field('name')->getRender();

// Render one or more fields without form tag | renderFields( array_fields, print(true(default)|false) )
$form->renderFields(['name', 'email', 'password']);

Helper methods

//Create html tags | setHtml( tag, attributes, content )
$form->setHtml('div', ['class'=>'col-md-12'], $form->render(false) );
// produce
.....
// filter elements | elements( array_keys, array_all, default_if_doesn't_exist ) $form->elements( ['name', 'passwords'], ['name'=>'Bob', 'password'=>'da6s57', 'date'=>'2015-11-18'] ); //produce array( 'name'=>'Bob', 'password'=>'da6s57' ); //convert array to key => value by defined | setOptions( array, key_field, key_label ) $arr = [ [ 'id'=> 0, 'name'=>'Bob', 'password'=>'da6s57', 'date'=>'2015-11-18' ], [ 'id'=> 1, 'name'=>'Ted', 'password'=>'cscsds', 'date'=>'2015-11-19' ] ] $form->field('users')->type('dropdown')->options( $form->setOptions( $arr, 'id', 'name' ) ); //produce array( [ 0=>'Bob', 1=>'Ted'] )

Public config vars

 public $fieldset = true;  
	public $fieldset_name = 'Inserir/Editar';
 	public $out_type = 'bootstrap';
	public $form_class = 'form-horizontal';
	public $form_action = '';
	public $parent_group = true;
	public $parent_group_tag = 'div';
	public $parent_group_class = 'form-group';
	public $label = true;
	public $label_tag = 'label';
	public $label_class = 'col-md-3 control-label';
	public $input_parent = true;
	public $input_parent_tag = 'div';
	public $input_parent_class = 'col-md-6';
	public $input_class = 'form-control';
	public $input_check = array('checkbox'=>'');
	public $btn_submit = true;
	public $btn_submit_config = array('type'=>'submit', 'name'=>'btn_submit', 'class'=>'btn btn-success', 'value'=>'Save');
	public $btn_cancel = true;
	public $btn_cancel_config = array('type'=>'button', 'name'=>'btn_cancel', 'class'=>'btn btn-danger', 'value'=>'Cancel', 'onclick'=>'javascript:history.back(-1);');
	public $submit_config = array('label_tag'=>'div');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.