views:

1413

answers:

5
+1  Q: 

PHP form class

I'm used to ASPNET and Django's methods of doing forms: nice object-orientated handlers, where you can specify regexes for validation and do everything in a very simple way.

After months living happily without it, I've had to come back to PHP for a project and noticed that everything I used to do with PHP forms (manual output, manual validation, extreme pain) was utter rubbish.

Is there a nice, simple and free class that does form generation and validation like it should be done?

Clonefish has the right idea, but it's way off on the price tag.

+3  A: 

Zend_Form

vartec
You have a good answer, but really didn't give a good explanation. I'd recommend also posting a tutorial like: http://akrabat.com/2008/02/21/simple-zend_form-example/
St. John Johnson
well, there is quick start section in documentation I've linked to: http://framework.zend.com/manual/en/zend.form.quickstart.html
vartec
Can it be used without the whole Zend Framework?
Oli
There are other frameworks. If your asking if it can be done in plain PHP... Well yeah, just like it can be done in plain Python without Django, and C# without ASP.NET.
vartec
Fair comment. I just expected there to be more than just Clonefish considering the popularity of non-framework PHP.
Oli
I think popularity of non-framework PHP passed few year ago. Nowadays even beginners use CMS-framework hybrids like Drupal or Joomla
vartec
There is even new term coined -- CMF - Content Management Framework (as opposed to Web Application Framework)
vartec
+1  A: 

Symphony forms

alex shishkin
+1  A: 

The simplest solution (rather than going through the process of learning another framework) turned out to be just writing the forms and their processing code in Django and pulling their output into the PHP using CURL.

FILTHY but it was quick, has all the power of Django and it works.

Oli
A: 

Here's another free alternative:

http://code.google.com/p/php-form-builder-class/

It lets you create a form with code like:

include("../class.form.php5");

$form = new form("form_elements");

$form->addHidden("cmd", "submit");
$form->addTextbox("Textbox:", "field0");
$form->addTextarea("Textarea:", "field1");

$form->render();

Pros:

  • Built in form validation (PHP and javascript)
  • Comes out of the box with integrations with jQuery UI, CKEditor/TinyMCE, Google Maps, tool tips, etc.
  • Really easy to get up and running and creating powerful forms

Cons, which eventually kept me from using it:

  • No fine grain control of form output. You can either render the whole form as a table or nothing.
  • No fieldsets

It's looks to be under active development, so might be worth keeping an eye out for future versions/improvements.

zlovelady
+2  A: 

I have recently used the project listed above - http://code.google.com/p/php-form-builder-class/ - in development and noticed that the latest release (version 1.0.3) replaces the table markup with a more flexible div layout that can be easily styled to render forms however you'd like. There are many examples that can help you get started quickly.

I would recommend this project.

nice. This seems promising
KennyCason