Zend_Form 0.2 Release
As the second official release of Zend_Form is uploaded, there are a couple major changes that could break previous uses of the component.
Unique IDs
A major issue with the 0.1 release was the storage container had no way to differentiate between multiple instances of a form being open. If a multi-page form was opened in one tab, for instance, and that same form was opened again in another tab, and the forms were completed concurrently, the data would be corrupted and one of the forms would revert back to the first page (due to it thinking that it was completed, when it was actually the other instance).
The fix for this is the implementation of unique Ids. Every multi-page form must implement a hidden field on the form named ‘__uniqueid’ as follows:
<input type="hidden" name="__uniqueid" value="<?=$this->form->uniqueId()?>" />
The only pre-requisite for calling the uniqueId() method is that the data storage container is set (as it should be on every page for multi-page form anyways).
IMPORTANT: Although it would be poor practice if this occurred, if the data source is not set before calling uniqueId() on a page following the first, then it will generate a new unique Id, which will result in your data not correctly being saved. This is because it does not find the __uniqueid string in the raw data, and therefore believes it is not on a subsequent page and generates a new Id for your form.
Other than implementing the hidden field, no other changes are necessary in your code, and the management of data for each instance will be handled behind the scenes.
This feature will still need polishing out so as always, feedback is very much appreciated and can be given by emailing me (my email is visible on the front page of this website).
Element Access Via Properties
Elements can now be accessed like class properties. The benefit of such a change is that pages can now be accessed or modified like so:
$form = new Zend_Form(); $form->addPage('my_page'); $form->my_page->addField('field'); $form->my_page->field->addValidator('Alnum');
Also, __toString() support has been added to fields which return the value of the field. This makes it much easier to implement value retention in forms:
<input type="text" name="first_name" value="<?=$this->form->first_name?>" />
If you wish to have a default value for a field, you can use the getValue() method on a field, where the first parameter is the default value:
<input type="text" name="first_name" value="<?=$this->form->first_name->getValue('Your First Name')?>" />If a first_name value exists, it will return that, but if it has not been submitted yet, it will return “Your First Name” instead.
Improved API Reference
I have gone through and extended at least half of the class and method documentation, adding detail. Although work still needs to be done in this area, it is much improved and can be viewed by clicking the link to the right. (It is always up-to-date as the latest revision in SVN)
