Conditionally set Zend Form select element multi-options based on current value
Currently I'm trying to build a web application in Zend framework.
But I can't figure out how to Manage status in my system
Eg I have the following status for my quote handling in the system
Awaiting for Confirmation
Asssigned
In Progress
Completed
Mark As Spam
I stored these values in a table called ProviderQuoteStatus and I created a function called ProviderQuoteStatus() in the zend_db class and uses the functi开发者_StackOverflow社区on to generate status values in zend form dropdown box.
$select = $this->select()->from("providerQuoteStatus",
array('key' => 'providerQuoteStatusId',
'value' => 'providerQuoteStatusName'));
$result = $this->fetchAll($select);
return $result->toArray();
Here is my Zend form code
$serviceType = new Application_Model_DbTable_ProviderQuoteStatus();
$serviceTypeValues = $serviceType->getProviderQuoteStatusFormValues();
$dropDownElement = new Zend_Form_Element_Select('providerQuoteStatus');
$dropDownElement->addMultiOptions($serviceTypeValues);
Everything working fine till this stage. If the quote in Asssigned Stage I only wanted the provider select these following options
Asssigned
In Progress
Completed
How can I remove 'Awaiting for Confirmation' and 'Mark As Spam' values in the Zend form dropdown box ?
Also where should I stored all these business logic (For example if the quote in Assigned Stage only can have Assigned, In Progress options etc)? In the Model DB class?
Thanks so much in advance :D
You could populate the select element with all the possible options in $form-init()
, as you are doing. But then modify the element during $form->setDefaults($defaults)
, at which point you will know the current value of the element and determine which options are no longer appropriate: if the element value is "Assigned", then remove the "Awaiting" and "Spam" options.
精彩评论