|
|||
|
Hello,
i'm looking for a quick&clean way (i'm asking too much.. i know ) to handle multipage forms. Since the Zend_Form component is still not fully complete (File Upload and Multi Page support are missing) i can't figure out finding a way to handle them without repeating much code. I tried to implement that code listed on the tutorial, but i found it incorrect, as there's some code which should go in the controller and not in the class extending zend_form or viceversa, and leads to a very tedious process in my case where i need different forms of this kind. At this point i will make a step back and move out of zend_form component until is 100% complete. Could you please post some examples (or links) on form handling without zend_form? Any help is appreciated. Thanks. |
|
|||
|
Hello,
Since i haven't found any solution to my issue, i managed to write something by myself. ![]() I wrote an external extensible class, which provides (or tries to do so) the following features: - Simple multi page form handling (all forms are extensions of my class) - Data persistence using sessions - Arbitrary step retrieving (in case you would edit some previous submitted step) - Data validation/filtering for each step - Stored data retrieving/deleting for each step But does NOT (yet?) provide the following: - Multi instance form handling (when the user opens multiple instances of the same form, using tabs for example, this uses the same session.. can't find a workaround for this) - Conditional step retrieving (i don't need this, at the moment, neither i've got any idea on how implement this) - Something else ![]() Dependencies: - Zend Framework version 1.5.1 - Zend_Form_* - Zend_Session_* - Zend_Controller_Request_Http Here's a code snippet from my controller, just to let you see how it works: PHP Code:
Just a little disclaimer: Quote:
Last edited by MiK : 04-10-2008 at 01:37 PM. |
|
|||
|
Hello,
I'm also trying to use multi page forms with Zend_Form following the tutorial but as you said it's wrong at some points. I think your code looks nice so, if it really works I'm interested on it. So, could you reply with the whole code? You know: controller, form class and view (.phtml files). It'd help me a lot ![]() Thanks and good job!! |
|
|||
|
Thanks for your interest.
Since i'm currently still developing the class, i don't have a "STABLE" release. Please allow a couple of days in order to let me build a working example, and so i will post the complete code as attachment here. One of my last edit was the ability to fetch an array of a subform elements ( Multipage_Form::getStepElements() ) in order to pass it directly to the view, and without being limited by zend_form decorators behaviour. Something like: PHP Code:
HTML Code:
<table> <tr> <td>{$form.field1->getLabel()}</td> <td>{$form.field1}</td> <tr> <td colspan="2">{$form.submit}</td> </tr> </table> |
|
|||
|
Finally i got it...
I created a little zend framework enviroment with a couple of very simple examples. Just copy the ZF libraries to /library/Zend and you're ready. The class is located in /library/Form All the forms are in /application/forms Download: MultiPage_Form_with_Examples.zip Class Documentation: MultiPage_Form_PhpDoc.zip Last edited by MiK : 04-12-2008 at 08:50 PM. |
|
|||
|
Thank you for your code MiK, it's really helpful! I like the idea of having only one controller action for all the steps, so it behaves as one page form.
It works in Virtual Host alright, but to make it work in a subdirectory of document root, you have to change the paths in views to make it work properly. This is a common problem. I managed that with the baseUrl() view helper, after setting FrontController->setBaseUrl(). |
|
|||
|
Nice to hear that someone thinks that my code is useful
![]() Thanks for your support.. FYI, I found that solution a bit limited because i haven't found a way to retrieve a particular subform depending on user selection. Take the example of a "Choose a type of payment" form where you have a dropdown box with values: "Cheque", "Credit Card", "Money Order" where each selection must end on a different form requesting payment details... (Conditional step retrieving). Another problem is that, since we use a static session namespace to persist data between steps, when the user opens multiple instances of the same form in his browser, this would overwrite session data.. Now, this class works well when you're using it on simple forms where you don't need these features, but when you have to handle complex forms it becomes useless... The only way i found to fix these issues is to span the form across multiple controller actions (without using this class), using a dynamically-created session id (eg. current timestamp) to create the namespace where to store form data preserving form uniqueness. Doing so, you will be able to fetch from every step action the previous inserted data and make your checks to have the correct form loaded (and implement conditional subforms). This is just a little note ![]() Hope this helps. Regards, Michele |
|
|||
|
Quote:
How could I get those path in view controller (tpl or phtml files)?
__________________
Amit Shah |
![]() |
| Thread Tools | |
| Display Modes | |
|
|