Welcome Guest, Not a member yet? Register   Sign In
CI Form-Framework 1.0.1 - a form abstraction layer
#1

[eluser]benboi[/eluser]
CI Form-Framework 1.0.1

Introduction
The CI Form-Framework is an abstraction-layer for the creation of forms in Codeigniter. Without having such extension, creating forms is a mess, because you have different places to create the logic and presentation of your forms and there are many things to adjust in a case of changig requirements.

This extension fixes that, by just combining some great components of the Codeigniter-Framework to one form-frameworkn and make them manageable in a centralized way, by handling forms equal to models.

Features
* Centralizes form-handling, presentation and logic in one place
* Uses Codeigniter components to get it done
* Lets you write less code for forms
* Makes it possible to reuse forms for different approaches
* Simplyfies input-handling by returning objects/arrays
* Everything is an object
* Values of a form be saved to session to have multi-page-form support
* A custom loader for use with hmvc-extension is provided

Requirements
This extension was developed and tested for Codeigniter-Reactor. The Core-Edition was not tested but maybe also works without a problem.

Libraries and helpers used by the extension are not needed to autoload, because the extension manages it by itself.

Installation
To install the "CI Form-Framework" get the most recent version of it from https://github.com/benboi/ci-form-framework first, then follow the next steps:

1. copy the application folder from the archive/checkout over your application folder
2. You are done already Wink

Documentation
The documentation can be found in the github repository or under http://benboi.net/code/ci-form-framework.

Changelog

08.06.2011 - 1.0
* added save to session functionality
* provides a customized hmvc loader
* fixed some bugs, like refilling radios and checkboxes

08.06.2011 - 1.0.1
* bugfix release
* added methods to check if session data form a form is set and to get the data from session as object.
#2

[eluser]darrentaytay[/eluser]
Had a quick skim through the source code and it looks very promising, I shall download it and try it out later Smile
#3

[eluser]benboi[/eluser]
Hey, just to give a quick preview, how this is working, im writing down some code here. Lets write a contact form:

The form-class (application/forms/contact_form.php)
Code:
<?php

class Contact_form extends CI_Form {

protected function setup() {

/* setting the form heading */
$this->option('legend', 'Please contact us!');

/* add the needed fields */
$this->add('input', 'prename');
$this->add('input', 'name');
$this->add('input', 'email');
$this->add('textarea', 'message');
$this->add('submit', 'submit');

/* change some options for each field */
$this->get('prename')->option('value', 'Your prename here ...');
$this->get('name')->option('value', 'Your name here ...');
$this->get('email')->option('value', 'Your email here ...');
$this->get('message')->option('value', 'Your message here ...');
$this->get('submit')->option('value', 'Send');

/* setup validation */
$this->get('prename')->rule('maxlength[40]|required');
$this->get('name')->rule('maxlength[40]|required');
$this->get('email')->rule('maxlength[40]|required|valid_email');
$this->get('message')->rule('required');

}

}

The controller (application/controller/contact.php)
Code:
<?php

Contact extends CI_Controller {

public function index() {

$this->load->form('contact_form');

if($this->input->post('submit')) {

if($this->contact_form->is_valid()) {
/* returns a std class with the user input */
$contactInformation = $this->contact_form->post();
/* do something */
}

}

$this->load->view('contact_view', array('contact_form' => $this->contact_form));

}

}

The view
Code:
<?php echo $contact_form; ?>

This is an really easy example, this extension is capable of a lot of more Wink

Ill keep you up to date an will create a documenation this week Wink
#4

[eluser]darrentaytay[/eluser]
I've not had a chance to have a proper go at this yet, but one thing that looks like it could be an improvement is method chaining, eg:

Code:
$this->add('input', 'prename')
     ->option('value', 'Your prename here ...')
     ->rule('required');

or even

Code:
$this->add('input', 'prename');

$this->get('prename')
     ->option('value', 'Your prename here ...')
     ->rule('required');

Makes it a bit neater and easier in my opinion but just a suggestion!
#5

[eluser]benboi[/eluser]
Thanks for your message. Chaining is already there, just didnt want to confuse you folks ^^

I see , there is big need to write that doc.
#6

[eluser]darrentaytay[/eluser]
Ahh I see, so how would it work? Like my example #1 or #2?
#7

[eluser]codeninja[/eluser]
This is brilliant.. Smile
#8

[eluser]benboi[/eluser]
Added a short documentation, look @ github Wink
#9

[eluser]benboi[/eluser]
Updatet post number one Wink
#10

[eluser]codeninja[/eluser]
Are you planning on adding support for multi-page forms (wizards)?




Theme © iAndrew 2016 - Forum software by © MyBB