readonly
readonly

Reputation: 356044

Alternative to PHP QuickForm?

I'm currently playing around with HTML_QuickForm for generating forms in PHP. It seems kind of limited in that it's hard to insert my own javascript or customizing the display and grouping of certain elements.

Are there any alternatives to QuickForm that might provide more flexibility?

Upvotes: 5

Views: 4345

Answers (6)

Kieran Hall
Kieran Hall

Reputation: 2627

I've found the Zend_Form package of the Zend Framework to be particulary flexible. This component can also be used with Zend_Dojo to rapidly implement common javascript form helpers. However, the component is agnostic when it comes to the library that you use, but supports Dojo naitively. The component also allows for grouping, multi-page forms, custom decorators, validators and other features making it very flexible.

Upvotes: 5

Sean McSomething
Sean McSomething

Reputation: 6517

I can't really say anything about it but, the other day, I ran across the clonefish form library. It looked promising enough to end up in my bookmarks list as a "look at this later".

Upvotes: 0

blockhead
blockhead

Reputation: 9705

With Zend_Form it is entirely possible to start with your form visually, and then work backwords.

This is done by removing all decorators and replacing them with a ViewScript decorator

$this->form->setDecorators( array(array('ViewScript', array('viewScript' => 'forms/aform.phtml'))));

And in that viewscript you would do something like this:

<?=$this->element->title->renderViewHelper()?>

Going with this approach, you can basically do anything you want with the form.

Another great thing about Zend_Form is that you can create custom elements which can encapsulate other stuff in them. For example, you can have an element which outputs a textarea and then some Javascript to turn it into a WYSIWYG area.

Upvotes: 1

gavinandresen
gavinandresen

Reputation: 551

I wrote an article about this for OnLamp: Autofilled PHP Forms

My beef with HTML_QuickForm and Zend_Form and all the other form-handling frameworks I could find is that they seem to assume that you'll be writing code to generate the form. But that didn't match my development process, where I'd start with the LOOK of the page (specified via HTML templates) and add functionality to it.

In my view of the world, form handling boils down to:

  1. Fetching the data that should go in the form to start (usually from a database).
  2. Fetching the HTML code for the form (usually a template).
  3. Mushing 1 and 2 together, and outputting the result.
  4. Getting the submitted form data and validating it.
  5. Re-displaying the form with error messages and the invalid data, OR
  6. Displaying the congratulations-your-data-was-ok page.

fillInFormValues() makes 2, 3, and 5 really easy.

Upvotes: 4

Andrew Taylor
Andrew Taylor

Reputation: 1850

I'll second Zend_Form; it has an excellent ini style implementation that allows you to define a form extremely quickly:

[main]
vessel.form.method = "post"

vessel.form.elements.name.type = "text"
vessel.form.elements.name.name = "name"
vessel.form.elements.name.options.label = "Name: "
vessel.form.elements.name.options.required = true

vessel.form.elements.identifier_type.type = "select"
vessel.form.elements.identifier_type.name = "identifier_type"
vessel.form.elements.identifier_type.options.label = "Identifier type: "
vessel.form.elements.identifier_type.options.required = true
vessel.form.elements.identifier_type.options.multioptions.IMO Number = "IMO Number";
vessel.form.elements.identifier_type.options.multioptions.Registry organisation and Number = "Registry organisation and Number";
vessel.form.elements.identifier_type.options.multioptions.SSR Number = "SSR Number";

vessel.form.elements.identifier.type = "text"
vessel.form.elements.identifier.name = "identifier"
vessel.form.elements.identifier.options.label = "Identifier: "
vessel.form.elements.identifier.options.required = true
vessel.form.elements.identifier.options.filters.lower.filter = "StringToUpper"

vessel.form.elements.email.type = "text"
vessel.form.elements.email.name = "email"
vessel.form.elements.email.options.label = "Email: "
vessel.form.elements.email.options.required = true

vessel.form.elements.owner_id.type = "hidden"
vessel.form.elements.owner_id.name = "owner_id"
vessel.form.elements.owner_id.options.required = true

; submit button
vessel.form.elements.submit.type = "submit"
vessel.form.elements.submit.name = "Update"
vessel.form.elements.submit.option.value = "Update"

Upvotes: 1

Konrad Rudolph
Konrad Rudolph

Reputation: 546193

If you find it hard to insert Javascript into the form elements, consider using a JavaScript framework such as Prototype or jQuery. There, you can centralize the task of injecting event handling into form controls.

By that, I mean that you won't need to insert event handlers into the HTML form code. Instead, you register those events from somewhere else. For example, in Prototype you would be able to write something like this:

$('myFormControl').observe('click', myClickFunction)

Also have a look at the answers to another question.

/EDIT: of course, you can also insert custom attributes and thus event handlers into the form elements using HTML_QuickForm. However, the above way is superior.

Upvotes: 5

Related Questions