zend framework - Zend_Form - multiple forms on same page -
If there are too many forms in one page, when I submit to one of them, how can I tell who Submitted?
I thought about creating uniqe id for each, and saving them as hidden areas and user sessions - while this is a solution, the problem is that to delete the old ID Not a good place.
Any better idea how to solve this problem?
Thanks in advance!
First of all: Have you considered sending two forms in two different actions? In this way you can control each form separately in each form each. If you are using the Zend MVV component then it should be "best practice".
The second option is to check the value of the submit button, which will be included in the request, e.g.
& lt; Input type = "submit" name = "save" value = "form1" /> // will include "form1" in PHP: // $ _POST ["save"] & input type = "submit" name = "save" value = "form2" /> // will contain "form2" in PHP: // $ _POST ["save"]
value
-attribute will be presented as buttons in the label.
So you want to distinguish the form with various submit-button names:
& lt; Input type = "submit" name = "save-form1" value = "submit" /> // will have "submit" in PHP: // $ _POST ["save-form1"]. Input type = "submit" name = "save-form 2" value = "submit" /> // in the "Submit-form2"] in PHP: // $ _POST ["save-form2"]
edit:
During commentary between OP and yourself, it seems possible solution:
class My_Form_Base Zend_Form Extended {Private Static $ _instanceCounter = 0; Public function __ composition ($ option = zero) {origin: __construct ($ option); Auto :: $ _ instanceCounter ++; $ This- & gt; Element ('hidden', 'form-id', sprintoff ('form-% s- example-% d', $ this-> _getFormType (), self: $ _ example quarters);} Safe _getFormType () {} Get_class ($ this);}} return_class (My_Form_Type1) My_Form_Base {public function init ()} {// more form initialization}} class My_Form_Type2 extends My_Form_Base {public function init () {// more form initialization}}
Comments
Post a Comment