The EZForm PHP Library

What is it ?

EZForm is a PHP library, consisting of two files :

  • ezform.inc.php : the PHP core library, i.e. the source code that enables you to use EZForm
  • ezform.css : the CSS file to custom the look of the forms generated by/with EZForm

This library needs at least PHP 5.1 (or 5.0 with SimpleXML library installed), and optionally a DBMS compatible with the PHP language.

What is it for ?

EZForm has one aim : make HTML forms production easier, faster, and business-logic oriented. To achieve this goal, it is based on two concepts, those who are really important when creating a form :

  • The data contained in the form : you describe them in a simple XML file, no matter how it will be displayed (except order).
  • The business logic behind each field and behind the whole form : you describe it in your PHP form page, through your own PHP functions.

And that’s all, you don’t need to produce anything more, everything is automatically generated by the EZForm library.

How does it works ?

In order yo create a new form, you may follow those simple steps :

  1. Create a new XML file describing your form data and validation rules (min/max values, max length, etc).
  2. Create your form file (.php), containing your standard page structure (menus,titles, logos, etc).
  3. Include the EZForm PHP library into this page, and call its basic functions (initialization and form generation)
  4. Write your business-logic functions, for every field that need one (typically login and password fields), and for the whole form processing in case of successful form validation.

And that’s all. Form generation, data validation, error tracking and display, business functions calls are automatically managed by the EZForm library.

How can I know if my XML file is correct ?

EZForm does not check if your XML file is correct, so you have to do it manually with the help of a specific DTD file to validate your form.

To write down and validate your XML files, I recommend the use of Cooktop, a really simple and powerful software for XML editing. It helps writing the XML tags, and it can validate your file from a DTD as simple as clicking on a button.

Can I customize my form look ?

Hopefully yes. You have two levels of customization possible :

  • The CSS file : change the CSS file to change the look of the auto-generated form, like you may do to custom your website look.
  • The manual form generation : Instead of letting EZForm automatically generates your form, you can use some provided functions to generate each field of the form manually. This way you can choose to add your own elements into the form, or to display it the way you want.

Please give me an example

No problem, just choose one of those options :

Can EZForm generate a data updating form ?

EZForm supports generating forms for both inserting and updating data, both in only one page/XML file. If you want to use the update mode, gather your initial data manually and give it to the EZForm class constructor. Everything is exactly the same for the rest.

A general algorithm that you may use in your PHP file to both cover the insert and update cases is :

  1. Check your own GET/POST data to know if you are in inserting or updating mode
  2. If inserting, just instanciate EZForm with empty inital data.
  3. If updating, then gather your initial data (typically from your database), and instanciate EZForm with this initial data.
  4. Let EZForm generate your form automatically.

Please note that in this case, you must write two form processing functions, one for inserting, and one for updating. EZForm will only call the good one, don’t bother about this. Those functions are specified in the header of the XML file. Have one more look to the example.

I want it now !

Okay, just click download and enjoy :)

Need more help ? Want to make a comment ?

Please send me back your experience by posting comments on this blog in the “EZForm” topic. It will help me to improve this useful (I hope) library.

A FAQ will be opened if some questions seems to be recurrent.

Laisser un commentaire

Vous devez être connecté pour poster un commentaire




Parse error: syntax error, unexpected '/' in /mnt/106/sda/6/e/prog13/wp-content/themes/freshy/footer.php on line 18