Coder Social home page Coder Social logo

wallter / codeigniter_bootstrap_form_builder Goto Github PK

View Code? Open in Web Editor NEW
84.0 24.0 67.0 155 KB

Codeigniter + Bootstrap 2/3 Form Builder

License: MIT License

PHP 100.00%
bootstrap-form-builder php form-builder form-builder-api bootstrap2 bootstrap3 codeigniter codeigniter-library

codeigniter_bootstrap_form_builder's Introduction

Codeigniter Bootstrap 3 Form Builder

Do you want to write forms 60% faster?

Or type 60% less?

Are you using Codegniter and Bootstrap 3?

Then this is the plugin for you!

CodeIgniter library to build form's styled with Bootstrap 3. It's got 5 steps:

  • Load Libraries
  • Open Form
  • Echo out the output of your chosen function
  • Close your form
  • Enjoy Easy form building
  1. Load Libraries ==============

Load the Codeigniter form helper, then load the form_builder library.

$this->load->helper('form');
$this->load->library('form_builder');
  1. Open Your form ==============
<?= $this->form_builder->open_form(array('action' => '')); ?>
  1. Echo out your form ==============
<?
/* Prepare variables */
$defaults_object_or_array_from_db = NULL;

$item = new stdClass;
$item->id = 33;
$item->description = '';

$years = range(intval(date('Y')), intval(date('Y')) + 20);
$months = array_map(function ($n) {
	return str_pad($n, 2, '0', STR_PAD_LEFT);
}, range(1, 12));

$exp_month_options = array_combine($months, $months);
$cc_exp_month = '05';

$exp_year_options = array_combine($years, $years);
$cc_exp_year = intval(date('Y')) + 5;

$input_span = 'pull-left ';

/* Build form */
echo $this->form_builder->build_form_horizontal(
		array(
				array(/* HIDDEN */
						'id' => 'id',
						'type' => 'hidden',
						'value' => $item->id
				),
				array(/* INPUT */
						'id' => 'color',
						'placeholder' => 'Item Color',
						'input_addons' => array(
								'pre' => 'color: #',
								'post' => ';'
						),
						'help' => 'this is a help block'
				),
				array(/* DROP DOWN */
						'id' => 'published',
						'type' => 'dropdown',
						'options' => array(
								'1' => 'Published',
								'2' => 'Disabled'
						)
				),
				array(/* TEXTAREA */
						'id' => 'description',
						'type' => 'textarea',
						'class' => 'wysihtml5',
						'placeholder' => 'Item Description (HTML or rich text)',
						'value' => html_entity_decode($item->description)
				),
				array(/* COMBINE */
						'id' => 'expiration_date',
						'type' => 'combine', /* use `combine` to put several input inside the same block */
						'elements' => array(
								array(
										'id' => 'cc_exp_month',
										'label' => 'Expiration Date',
										'autocomplete' => 'cc-exp-month',
										'type' => 'dropdown',
										'options' => $exp_month_options,
										'class' => $input_span . 'required input-small',
										'required' => '',
										'data-items' => '4',
										'pattern' => '\d{1,2}',
										'style' => 'width: auto;',
										'value' => (isset($cc_exp_month) ? $cc_exp_month : '')
								),
								array(
										'id' => 'cc_exp_year',
										'label' => 'Expiration Date',
										'autocomplete' => 'cc-exp-year',
										'type' => 'dropdown',
										'options' => $exp_year_options,
										'class' => $input_span . 'required input-small',
										'required' => '',
										'data-items' => '4',
										'pattern' => '\d{4}',
										'style' => 'width: auto; margin-left: 5px;',
										'value' => (isset($cc_exp_year) ? $cc_exp_year : '')
								)
						)
				),
				array(/* DATE */
						'id' => 'date',
						'type' => 'date'
				),
				array(/* CHECKBOX */
						'id' => 'checkbox_group',
						'label' => 'Checkboxes',
						'type' => 'checkbox',
						'options' => array(
								array(
										'id' => 'checkbox1',
										'value' => 1
										// If no label is set, the value will be used
								),
								array(
										'id' => 'checkbox2',
										'value' => 2,
										'label' => 'Two'
								)
						)
				),
				array(/* RADIO */
						'id' => 'radio_group',
						'label' => 'Radio buttons',
						'type' => 'radio',
						'options' => array(
								array(
										'id' => 'radio_button_yes',
										'value' => 1,
										'label' => 'Yes'
								),
								array(
										'id' => 'radio_button_no',
										'value' => 0,
										'label' => 'No'
								)
						)
				),
				array(/* SUBMIT */
						'id' => 'submit',
						'type' => 'submit'
				)
		), $defaults_object_or_array_from_db);

echo $this->form_builder->close_form();
?>
  1. Close The Form ==============
<?= $this->form_builder->close_form(); ?>

Produces:

<form action="" class="form-horizontal col-sm-12" autocomplete="on" enctype="multipart/form-data" method="post" accept-charset="utf-8">
	<input type="hidden" name="id" value="33" />
	<div class="form-group">
		<label for="color" class="col-sm-2 control-label">Color</label>
		<div class="col-sm-9">
			<div class="input-group">
				<span class="input-group-addon">color: #</span>
				<input type="text" name="color" value="" id="color" placeholder="Item Color" class="form-control"  />
				<span class="input-group-addon">;</span>
			</div>
			<span class="help-block">this is a help block</span>
		</div>
	</div>
	<div class="form-group">
		<label for="published" class="col-sm-2 control-label">Published</label>
		<div class="col-sm-9">
			<select name="published" id="published" class="valid form-control">
				<option value="1">Published</option>
				<option value="2">Disabled</option>
			</select>
		</div>
	</div>
	<div class="form-group">
		<label for="description" class="col-sm-2 control-label">Description</label>
		<div class="col-sm-9">
			<textarea name="description" cols="40" rows="10" id="description" class="form-control wysihtml5" placeholder="Item Description (HTML or rich text)" ></textarea>
		</div>
	</div>
	<div class="form-group">
		<label for="expiration_date" class="col-sm-2 control-label">Expiration Date</label>
		<div class="col-sm-9">
			<select name="cc_exp_month" id="cc_exp_month" label="Expiration Date" autocomplete="cc-exp-month" class="pull-left required input-small valid form-control" required="" data-items="4" pattern="\d{1,2}" style="width: auto;">
				<option value="01">01</option>
				<option value="02">02</option>
				<option value="03">03</option>
				<option value="04">04</option>
				<option value="05" selected="selected">05</option>
				<option value="06">06</option>
				<option value="07">07</option>
				<option value="08">08</option>
				<option value="09">09</option>
				<option value="10">10</option>
				<option value="11">11</option>
				<option value="12">12</option>
			</select>
			<select name="cc_exp_year" id="cc_exp_year" label="Expiration Date" autocomplete="cc-exp-year" class="pull-left required input-small valid form-control" required="" data-items="4" pattern="\d{4}" style="width: auto; margin-left: 5px;">
				<option value="2016">2016</option>
				<option value="2017">2017</option>
				<option value="2018">2018</option>
				<option value="2019">2019</option>
				<option value="2020">2020</option>
				<option value="2021" selected="selected">2021</option>
				<option value="2022">2022</option>
				<option value="2023">2023</option>
				<option value="2024">2024</option>
				<option value="2025">2025</option>
				<option value="2026">2026</option>
				<option value="2027">2027</option>
				<option value="2028">2028</option>
				<option value="2029">2029</option>
				<option value="2030">2030</option>
				<option value="2031">2031</option>
				<option value="2032">2032</option>
				<option value="2033">2033</option>
				<option value="2034">2034</option>
				<option value="2035">2035</option>
				<option value="2036">2036</option>
			</select>
		</div>
	</div>
	<div class="form-group">
		<label for="date" class="col-sm-2 control-label">Date</label>
		<div class="col-sm-9">
			<input type="date" name="date" value="" id="date" class="form-control"  />
		</div>
	</div>
	<div class="form-group">
		<label for="checkbox_group" class="col-sm-2 control-label">Checkboxes</label>
		<div class="col-sm-9">
			<label class="checkbox-inline">
				<input type="checkbox" name="checkbox_group" value="1" id="checkbox_group" label="1"  />
				1
			</label>
			<label class="checkbox-inline">
				<input type="checkbox" name="checkbox_group" value="2" id="checkbox_group" label="Two"  />
				Two
			</label>
		</div>
	</div>
	<div class="form-group">
		<label for="radio_group" class="col-sm-2 control-label">Radio buttons</label>
		<div class="col-sm-9">
			<label class="radio-inline">
				<input type="radio" name="radio_group" value="1" id="radio_group" label="Yes"  />
				Yes
			</label>
			<label class="radio-inline">
				<input type="radio" name="radio_group" value="0" id="radio_group" label="No"  />
				No
			</label>
		</div>
	</div>
	<div class="form-group">
		<label for="submit" class="col-sm-2 control-label">
		</label>
		<div class="col-sm-9">
			<input type="submit" name="submit" value="Submit"  class="btn btn-primary" name="submit" value="" />
		</div>
	</div>
</form>

ScreenShot

codeigniter_bootstrap_form_builder's People

Contributors

groovenectar avatar shakespeare2000 avatar wallter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter_bootstrap_form_builder's Issues

File Upload Input

Is there a way to specify a file input? how can it be achievable?:

Answer:

array(/* INPUT */
'id' => 'file_upload',
'placeholder' => 'Item Color',
'type' => 'file',
)

possible found some glitches (submit-button, select-field) ...

Hi!
Just installed your library. Great to use!
But I think I found some minor errors:

  1. the select-field generates attributes without separating spaces. Fixed this locally by adding an extra space in function _create_extra_string():
    old:
  $extra .= "{$k}=\"{$v}\""; 

new:

  $extra .= " {$k}=\"{$v}\""; 
  1. the submit-field generates the name and value-attibutes twice, so I changed the function _build_input():
            case 'form_submit':
                $name = $this->elm_options['id'];
                $label = $this->_make_label((isset($this->elm_options['label']) ? $this->elm_options['label'] : $this->elm_options['id']));

                // CHANGED:
                unset($this->elm_options['id']); // new
                unset($this->elm_options['label']); // new
                /* DELETED:
                if (!isset($this->elm_options['value'])) {
                    unset($this->elm_options['name']);
                }
                */

Now the errors in html are fixed. Maybe you'll have a look and can implement this as well ?

Still have some trouble when putting a form into a bootstrap "panel", the panel-size is not increased, so the form runs out of the panel.So I've to check this further ..

Thanks for that library !

Knut

using: codeigniter V.3.0.rc3, bootstrap 3.3.4, grocery-crud.1.5.1,font-awesome 4.3

radio button default

how can you set a default value for a group of radio buttons, so that one of them is pre-selected? or a checkbox?

Parsing Error

syntax error, unexpected ''open_form'' (T_CONSTANT_ENCAPSED_STRING), expecting ')'

Howto doing cascading dropdown

Hi wallter,
great job! Love your lib.

  • Howto build a cascading dopdown with your lib?
  • howto make forms uver tabs?
    Thanks for any help

BR
Gregor

lone checkbox

Is there a way to do suppress one of the labels for the checkbox group? Right now, if only one checkbox is included, it has two labels: one for the group, and one for the box itself.

only errors :D

there is only errors :D how can i use this?does it work for codeigniter 2.1 or even codeigniter 3?

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.