【问题标题】:Zend Framework, Form - Form renders with just one fieldZend Framework, Form - 仅使用一个字段呈现表单
【发布时间】:2011-10-13 10:33:57
【问题描述】:

我正在使用 ZF Form 来生成表单。 我写了一堂课

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

        $name = $this->createElement('text', 'email',array('label'=>'Name','size'=>'50')); 
        $name->setErrorMessages(array('Field is required'));
        $name->setRequired(TRUE);       
        $this->addElement($name);

        $contact_person = $this->createElement('text', 'email',array('label'=>'Contact person','size'=>'50')); 
        $contact_person->setErrorMessages(array('Field is required'));      
        $contact_person->setRequired(TRUE);                 
        $this->addElement($contact_person);

        // add element: submit button
        $submit = $this->createElement('submit', 'submit', array('label' => 'Save'));
        //$submit->setDecorators(array('ViewHelper')); 
        $this->addElement($submit); 

        $btn = $this->createElement('button', 'cancel', array('label' => 'Cancel'));
        $btn->setAttribs(array('onClick'=>'window.location="/system/login"','style'=>''));
        //$btn->setDecorators(array('ViewHelper')); 
        $this->addElement($btn); 
    }
}

在我的控制器中,我有

public function editAction()
{
    $frmClient = new Form_Client();
    $frmClient->setAction('edit');

    /*submit*/
    if ($this->_request->isPost()) { 
            if ($frmClient->isValid($_POST)) { 
                $data = $frmClient->getValues();
            }
    }

    $this->view->form = $frmClient;
    $this->_helper->viewRenderer('form');
}

在我看来有

<?php echo $this->form; ?>

问题在于表单仅使用第一个输入字段呈现。 你知道这有什么问题吗?

谢谢, 雅各布

【问题讨论】:

    标签: php forms zend-framework frameworks zend-form


    【解决方案1】:

    您的两个文本字段都称为“电子邮件” - 每个字段都必须有一个唯一的名称。

    【讨论】:

      【解决方案2】:

      目前,两个表单元素具有相同的名称。尝试类似:

      [..]
      $name = $this->createElement('text', 'name',array('label'=>'Name','size'=>'50'));
      [..]
      $contact_person = $this->createElement('text', 'contact_person',array('label'=>'Contact person','size'=>'50'));
      [..]
      

      【讨论】:

        猜你喜欢
        • 2018-04-19
        • 1970-01-01
        • 2021-11-15
        • 1970-01-01
        • 2014-06-21
        • 2017-01-08
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多