1

我是 Zend Framework 的新手,我有一个问题是,如果我在一个表单中有两个 Zend_Form_Element_Text,并且我想让它们中的任何一个由用户填写。

例如,电话号码和手机号码。人们只需要输入其中一个即可继续。

我要怎么做?谢谢

4

1 回答 1

0

嗨,我认为您可以执行以下操作。

如果您在控制器操作中初始化表单,请尝试以下操作:

/**
 * IndexAction
 *
 * @return void
 */
public function indexAction() {

    // initalize your form
    $form = new MyForm();

    // get post data
    $post = $this->_request->getPost();

    // check if phone number is empty

    if (! empty($post['phone_number'])) {

        // remove validator from mobile phone element
        $mobile = $form->getElement('mobile');
        $mobile->removeValidator('notEmpty');
        $mobile->setRequired(false);
    }

    if ($form->isValid($this->getRequest()->getPost())) {
        $input = $form->getValues();

        // do something with the input
        print_r($input, true);
    }
}
于 2009-09-30T05:33:52.763 回答