0

下面是我的 Zend_Form 文件(抱歉间距太小了)!!

<?
class Form_Participant extends Zend_Form
{
public function init()
{
    $role = new Zend_Form_Element_Radio('role');
    $role->setRequired(true)
               ->setLabel('Role at Competition*')
               ->setMultiOptions(array('Competitor','Coach'),array(0,1))
               ->setDecorators($this->container());
    $this->addElement($role);

    $salutation = new Zend_Form_Element_Radio('salutation');
    $salutation->setRequired(true)
               ->setLabel('Salutation/Title')
               ->setMultiOptions(array('Mr.','Mrs.','Miss.','Ms.','Dr.','Other'),array(0,1,2,3,4,5))
               ->setDecorators($this->container());
    $this->addElement($salutation);     

    $first_name = new Zend_Form_Element_Text('first_name');
    $first_name->setRequired(true)
               ->setLabel('First Name')
               ->setDecorators($this->container());
    $this->addElement($first_name);

    $last_name = new Zend_Form_Element_Text('last_name');
    $last_name->setRequired(true)
              ->setLabel('Last Name')
              ->setDecorators($this->container());
    $this->addElement($last_name);

    $preferred_name = new Zend_Form_Element_Text('preferred_name');
    $preferred_name->setRequired(false)
                   ->setLabel('Preferred Name (optional)')
                   ->setDecorators($this->container());
    $this->addElement($preferred_name);

    $gender = new Zend_Form_Element_Select('gender');
    $gender->setRequired(true)
           ->setLabel('Gender')
           ->addMultiOptions(array('Female','Male'),array('0','1'))
           ->setDecorators($this->container());
    $this->addElement($gender);


    $email_address = new Zend_Form_Element_Text('email');
    $email_address->setRequired(true)
                  ->setLabel('Email Address')
                  ->setDecorators($this->container());
    $this->addElement($email_address);

    $year = new Zend_Form_Element_Radio('year');
    $year->setRequired(true)
               ->setLabel('Year of Study')
               ->setMultiOptions(array('1st Year','2nd Year','3rd Year','4th Year','5th Year','Other'),array(1,2,3,4,5,6))
               ->setDecorators($this->container());
    $this->addElement($year);

    $major = new Zend_Form_Element_Text('major');
    $major->setRequired(true)
          ->setLabel('Major/Specialization')
          ->setDecorators($this->container());
    $this->addElement($major);

    $resume = new Zend_Form_Element_File('resume');
    $resume->setRequired(false)
           ->setLabel('Upload Resume (PDF format)')
           ->setDestination(APPLICATION_PATH . '/../public/schools/2013/resume')
           ->setDecorators($this->container());
    $this->addElement($resume);


    $food_preference = new Zend_Form_Element_Textarea('food_preference');
    $food_preference->setRequired(false)
                    ->setLabel('Dietary Restrictions/Allergies (optional)')
                    ->setDecorators($this->container());
    $this->addElement($food_preference);

    $disabilities = new Zend_Form_Element_Textarea('disabilities');
    $disabilities->setRequired(false)
                    ->setLabel('Do you have any disabilities? (optional)')
                    ->setDecorators($this->container());
    $this->addElement($disabilities);

    $emergency_contact = new Zend_Form_Element_Textarea('emergency_contact');
    $emergency_contact->setRequired(true)
                    ->setLabel('Emergency Contact')
                    ->setDecorators($this->container());
    $this->addElement($emergency_contact);

    $additional_info = new Zend_Form_Element_Textarea('additional_info');
    $additional_info->setRequired(false)
                    ->setLabel('Additional Information (optional)')
                    ->setDecorators($this->container());
    $this->addElement($additional_info);

    $this->addElement('submit', 'register_participant_submit', array('label' => 'Add Participant','class'=>'blue_button add_participant'));
}

private function container()
{
    return array(
                    'ViewHelper',
                    'Errors',
                    array('Description', array('tag' => 'p', 'class' => 'description')),
                    array('HtmlTag', array('tag' => 'dd', 'id'  => array('callback' => array(get_class($this), 'resolveElementId')))),
                    array('Label', array('tag' => 'dt')),
                    array(array('elementContainer' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element-container')),
                );
}

 }

那里也有一个 Element_File。没有它,一切正常。有了它,表格根本不显示!

这就是我在控制器中调用表单的方式:

 $Form_Participant = new Form_Participant();
 $Form_Participant->setMethod('post')
                  ->setAttrib('id','registration_form')
                  ->setAttrib('enctype', 'multipart/form-data');

这里有什么问题?

4

1 回答 1

0

File 元素必须包含“File”装饰器,否则将不会呈现。如果您检查错误日志,您可能会在其中看到异常。您需要处理文件元素的装饰器与处理其他装饰器的方式略有不同,如下所示:

private function fileContainer()
{
    return array(
        'File',
        'Errors',
        array('Description', array('tag' => 'p', 'class' => 'description')),
        array('HtmlTag', array('tag' => 'dd', 'id'  => array('callback' => array(get_class($this), 'resolveElementId')))),
        array('Label', array('tag' => 'dt')),
        array(array('elementContainer' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element-container')),
    );
}
于 2013-02-09T00:34:52.920 回答