Home > Formmable_helper

Formmable_helper

Formmable_helper is a project mainly written in PHP, it's free.

A collection of php functions to aid in the creation of forms

h2. Formmable Helper

h3. What is it?

The Formmable helper is a simple collection of PHP fuctions to aid in the creation of form in web applications. It was designed to be used with Ellis Lab's "CodeIgniter":http://codeigniter.com PHP framework, but can be easily used in any PHP environment.

h3. Installation/Inclusion

If you are using CodeIgniter, all you have to do is copy the formmable_helper.php file into the @/system/application/helpers@ folder, then initiate it either in your @/system/config/autoload.php@ file or per controller in the method. ("CodeIgniter Docs on using Helpers":http://codeigniter.com/user_guide/general/helpers.html)

If you are not using CodeIgniter, just include the PHP file where you want to use it and you will have access to all the functions.

h3. How to Use

There is basically one function you will use for most of your code generation. It is the @form_item()@ function. It takes four arguments. They are:

  • @$type@ string (required; default is "text") ** Options are: @text@, @textarea@, @select@, @multiselect@, @radio@, or @checkbox@
  • @$name@ string (required)
  • @$label@ string (optional; used in the @@ tag; No value will give you no label tag)
  • @$more@ array (optional; all other options are sent as key/value pairs as part of this array)

The items that the more array will take are:

  • @$options => array()@ (For selects, multiselects, radio buttons, and check boxes this is an array of key/value pairs. The key will be the value; the value will be the displayed text.)
  • @$selected => string@ (For inputs that have options (see above) this should match the key (which is the HTML attribute @value@) of the selected option)
  • @$attributes => array()@ (HTML attributes as key/value pairs for the input)
  • @$value => string@ (For text and textareas, this is the initial value)
  • @$help_text@ => string (Help text that will be printed below the input)

h3. Outputted HTML

All HTML will be output in the following format:

@

@ @@ @
@ @@ @
$more['help_text']
@ @
@ @
@

The reasoning behind this format is it allows a high level of flexibility in how the form is displayed, while using as little markup as possible (no tables, no unneeded wrappers, etc). Others might prefer other formats, but this is what I found to be the most flexible. (I will write out more thoughts on this later, but for now that's all I will say.)

h3. Questions

If you have questions or have found points for improvement, let me know. You sould be able to contact me through github.com/rewdy

p.s. There are a few things I know need to be enhanced immediately, and I'll be making those updates soon.

Previous:gtksourceview