有一种简单的方法可以禁用Zend_Form错误吗?

I am using Zend Framework. For a particular form, there is not enough space to show the errors next to the form elements. Instead, I want to be able to display the errors above the form. I imagine I can accomplish this by passing $form->getErrorMessages() to the view but how do I disable error messages from being shown be each element?

You can add decorators to form elements using setElementDecorators. Zend_Form has a function called just after init entitled loadDefaultDecorators. In your subclass, you can override this like so:

/**
 * Load the default decorators for forms.
 */
public function loadDefaultDecorators()
{
    // -- wipe all
    $this->clearDecorators();

    // -- just add form elements
    // -- this is the default
    $this->setDecorators(array(
       'FormElements',
        array('HtmlTag', array('tag' => 'dl')),
        'Form'
    ));

    // -- form element decorators
    $this->setElementDecorators(array(
        "ViewHelper",
        array("Label"),
        array("HtmlTag", array(
            "tag"   => "div",
            "class" =>"element",
        )),
    ));

    return $this;
}

Assuming you added your elements in init, that applies those decorators to each element in the form. You'll note the absence of the "Errors" decorator in setElementDecorators. You could also try looping through the form elements and using removeDecorator to remove just the Errors decorator.

The proposal above does not take into account that the default decorators may change. Instead of clearing the decorators and then reapplying all except the ones you do not need, it would be better to disable the decorators you don't need at form-initialization time, like:

class My_Form_Login extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');        

        $username = new Zend_Form_Element_Text('auth_username');
        $username->setLabel('Username')
            ->setRequired(true)
            ->addValidator('NotEmpty')
            ->removeDecorator('Errors')
            ->addErrorMessage("Please submit a username.");
    etc.....

You could then, wherever you use the form, decide how to display the messages (if you're planning to display them apart from your form). Of course if they should be part of the form, just create a suitable decorator and add it to the form-element init method above. Here is a nice tutorial on form decorators from ZendCasts.com

Example of displaying messages apart from the form itself.

$elementMessages = $this->view->form->getMessages();

// if there actually are some messages
if (is_array($elementMessages)) 
{
    foreach ($elementMessages as $element)
    {
        foreach ($element as $message)
        {
            $this->view->priorityMessenger($message, 'notice');
        }
    }
}

The priorityMessenger-helper used above can be found here: http://emanaton.com/code/php/zendprioritymessenger