Pieforms 0.2.2

Pieforms project provides a simple, unified way to create, validate and process forms.
Pieforms project provides a simple, unified way to create, validate and process forms all with a common look and feel, with support for pluggable elements, renderers and validation rules.

Huh? What does all that mean?

In simple terms, Pieforms provides a library for building HTML forms. So rather than writing all that HTML yourself for building forms, handling the validation and processing of them in whatever messy, inconsistent way you're doing it currently, you simply define a big hash in your script that describes your form. Pieforms does all of the legwork involved with building the form HTML from this hash (using elements and renderers), and also handles the validation of input using rules. In the general case, after you've defined you form, all you need to do is write a callback function that gets called when the form has been submitted with the data valid according to the rules.

Sounds interesting! Show me an example...

Okay, so you're writing a simple form that has a standard < input type="text" > and a textarea on it, with a submit button. You'd write a script similar to the following:

require_once('pieform.php');
$form = array(
'name' => 'myform',
'method' => 'get',
'elements' => array(
'text' => array(
'type' => 'text',
'title' => 'Text Element',
'description' => 'A little text box for you'
'rules' => array(
'required' => true
)
),
'textarea' => array(
'type' => 'textarea',
'title' => 'Textarea',
'defaultvalue' => 'Some default text for the textarea',
'rows' => 7,
'cols' => 50
),
'submit' => array(
'type' => 'submit',
'value' => 'Submit form!'
)
)
);

echo pieform($form);

function myform_submit($values) {
echo "Your submitted values:< br >";
foreach ($values as $key => $value) {
echo "$key: $value< br> ";
}
}

You see how easy that is? You didn't have to write any HTML - in fact, the entire definition is in PHP, which means if you make mistakes they'll show up as parse errors, rather than HTML validity errors (which are generally less often checked for). You only called one function to have everything done for you. And you can write a function to handle submission, full well knowing that the text element will always have a value that isn't the empty string.

After that, the submnit function is almost academic. You just save whatever you want to the database or whatever, and then the last thing you should do is redirect the user somewhere, perhaps to the same page or perhaps elsewhere.

For AJAX forms, all you have to do is add 'ajaxpost' => true in the $form array, and then make your submit function output JSON in the form {'error': [false or true], 'message': 'some message'}, and then exit. Pieforms includes an implementation of json_encode for your convenience.

Okay, that looks easy! What else can it do?

The best part is that the elements, renderers and rules for your forms are pluggable. For example, you could write a 'wysiwyg' element which behaves like the textarea one, but also includes javascript necessary to turn the textarea into a full WYSIWYG editor. Or you could write an element with two select boxes, arrows to move items left and right, and AJAX searching of the boxes. The possibilities are limitless! You can also write your own rules for reuse later (and change how elements respond to those rules if necessary), and write your own renderers (which handle the HTML surrounding the elements), so you can do things like add a little help icon next to each element with a link to a page explaining how the element works.

Requirements:

You've downloaded the PHP5 version of Pieforms. With some reasonably minimal hacking it could be made to work with PHP4 (by making sure that the $form object is passed around by reference with the & operator, removing some PHP5 keywords like 'public' and 'private', and changing error handling to not involve throwing exceptions), I am not going to do the work involved unless I need it. If you want, you could get it working and provide a patch, which I would maintain as a separate tree. But in reality, you should think about moving your project to PHP5.

Installation:

1) Copy the 'pieform.php' file and the 'pieform' directory to somewhere in your application's include path (later versions will remove the requirement that Pieforms be in your include path). Also copy the 'JSON' directory to the same place if you do not have the JSON extension for PHP available and want to use the AJAX form submission support.

2) If you wish to use the AJAX form submission support, copy the 'MochiKit.js' file to wherever you are placing your javascript files for your application. If you are already using MochiKit, you can skip this step.

What's New in This Release:

This release contains a few bugfixes and the beginnings of a documentation manual.

last updated on:
April 9th, 2007, 23:35 GMT
price:
FREE!
developed by:
Nigel McNie
homepage:
pieforms.sourceforge.net
license type:
GPL (GNU General Public License) 
category:
ROOT \ Internet \ HTTP (WWW)

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Add your review!

SUBMIT