You need to move the sql query out of the forms init() method which gets called by the constructor (and before you get chance to set the user id). if the results of the sql query are only needed at render time (rather than at validation time) then you might override the forms render() method, do your sql query there and then call parent::render()
/* My Form */
public function render($view = null)
{
/* SQL here */
return parent::render($view);
}
EDIT:
Ok, here's what I would do:
class My_Form extends Zend_Form
{
private $_userId = null;
/* Getter and Setter for user id here */
public function init()
{
...
$this->createElement('Select', 'nameOfTheSelectElem',
array(
/* Don't add the multiOptions here */
)
);
}
private function _addMultiOptionsForMySelectElem()
{
/* SQL Query here */
$this->nameOfTheSelectElem->setMultiOptions($resultsOfTheSQLQuery);
}
public function render($view = null)
{
$this->_addMultiOptionsForMySelectElem();
return parent::render($view);
}
public function isValid($data)
{
$this->_addMultiOptionsForMySelectElem();
return parent::isValid($data);
}
}
So in the init method you can create the element, but don't add the options to the element at this point. Create a private method to do the sql query and add the options to the select element and then call the private method from the render method and the isValid method.
Hope that's clearer now. Is it?