To dynamically load countries you should use it the way you did:
I have done this previously with standard php and jquery
And here is nothing to do with Zend_Form. You should have a JSON service (for e.g.) that will accept CountryID and will return all states available.
For this purpose you should connect jQuery library in your <head> section.
$this->view->headScript()->appendFile('/js/jquery-1.7.3.js'); // In your Controller
Add you jQuery script to your template which will handle all events like this:
$_form->inlineScript()->appendScript(' // my raw JS here');
or
$_form->inlineScript()->appendFile('js/dynamicCountry.js'); // if you want to keep it in separate file
And here you are, nothing to do with Zend_From except assigning correct elements ID's, classes or names.
And for your service you can do smth. similar. Suppose URL http://localhost/mysite/service/states/country/AT
/**
* In your Service controller disable rendering for your layout and views
*/
public function preDispatch() {
$this->_helper->layout()->disableLayout(); // if you have `layout` enabled
$this->_helper->viewRenderer->setNoRender(true);
}
and ... welcome
public function statesAction() {
$request = $this->getRequest();
/**
* Country code transmitted through the parameter
* @var string
*/
$country = $request->getParam('country');
// you are free to do whatever you want and return JSON (for e.g.)
}