Pues lo que te indicó GatorV es correcto. Con JS lo puedes hacer, solo tienes que indicar en el formulario que el segundo campo tenga
setRegisterInArrayValidator(false) para que zend no interprete los valores que tiene ya que si no te dará un mensaje de que el valor escogido no está en el haytack. Algo así debes tener en el zend_form
/application/forms/Form.php
Código PHP:
Ver original<?php
class Application_Form_Form extends Zend_Form
{
public function init()
{
$this->setDecorators(
'FormElements',
'Form',
)
);
$foo = new Zend_Form_Element_Select('foo');
$foo->setLabel('Foo:')
->setDecorators(
'Errors',
'ViewHelper',
)
)
->setRequired(true)
->addMultiOptions(
'' => '[Foo]',
'foo' => 'Foo',
'bar' => 'Bar',
'candy' => 'Candy'
)
);
$bar = new Zend_Form_Element_Select('bar');
$bar->setLabel('Bar:')
->setDecorators(
'Errors',
'ViewHelper',
)
)
->setRequired(true)
->setRegisterInArrayValidator(false)
->addMultiOptions(
'' => '[Foo]'
)
);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Add Tour')
->setOptions(array('class' => 'submit')) ->setDecorators(
)
);
// attach elements to form
$this->addElements(
$foo,
$bar,
$submit,
)
);
}
}
/application/controllers/IndexController.php
Código PHP:
Ver original<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
$form = new Application_Form_Form();
$form->setAction('/')
->setMethod('post');
$this->view->form = $form;
if($this->getRequest()->isPost()){
if($form->isValid($this->getRequest()->getPost())){
}
}
}
}
/application/views/scripts/index.phtml
Código PHP:
Ver original<?php
$this->headScript()
->appendScript('var arrOpt = new Array();
arrOpt["foo"] = new Array();
arrOpt["foo"]["1_foo1"] = new Array();
arrOpt["foo"]["2_foo2"] = new Array();
arrOpt["foo"]["3_foo3"] = new Array();
arrOpt["bar"] = new Array();
arrOpt["bar"]["1_bar3"] = new Array();
arrOpt["bar"]["2_bar2"] = new Array();
arrOpt["bar"]["3_bar3"] = new Array();
arrOpt["candy"] = new Array();
arrOpt["candy"]["1_candy1"] = new Array();
arrOpt["candy"]["2_candy2"] = new Array();
arrOpt["candy"]["3_candy3"] = new Array();
var fIndexSession = 0;
var sIndexSession = 0;
function addEvent(obj,type,fun){
if(obj.addEventListener){
obj.addEventListener(type,fun,false);
}else if(obj.attachEvent){
var f=function(){
fun.call(obj,window.event);
}
obj.attachEvent("on"+type,f);
obj[fun.toString()+type]=f;
}else{
obj["on"+type]=fun;
}
}
function nullOptions(obj){
var n=obj.options.length
for (i=0;i<n;i++){
obj.options[i]=null
}
obj.options.length=0;
}
window.onload = function(){
addEvent(document.getElementById("foo"), "change", function(){
var f = this;
var fIndex = f.selectedIndex;
var s = document.getElementById("bar");
var sIndex = fIndexSession == fIndex ? s.selectedIndex : 0;
nullOptions(s);
sText = fIndex > 0
? "Bar"
: "Foo";
s.options[0] = new Option("[" + sText + "]", "", true);
fIndexSession = fIndex;
sIndexSession = sIndex;
for(var i in arrOpt){
if(i == f.value){
var n = 1;
for(var ii in arrOpt[i]){
sKey = ii.split("_");
bool = sIndex == n ? true : false;
s.options[n++] = new Option(sKey[1], sKey[0], false, bool);
}
}
}
});
}');
echo $this->headScript();
echo $this->form;
?>