0
public function emailAction()
{

    $form = new Application_Form_Email();
    $form->submit->setLabel('Send Email!');
    $this->view->form = $form;

    if ($this->getRequest()->isPost()) {    //check if add button is click
        echo "hi";
        $formData = $this->getRequest()->getPost('email');
        var_dump($formData);
        if ($form->isValid($formData)) { //check if form is valid 

            $emailaddress = $this->getRequest()->getPost();
            //$emailaddress = $this->getPost();
            var_dump($emailaddress);
            $db = new Application_Model_DbTable_Email();
            $db->sendEmail($emailaddress);



        } 
    }
}

嗨,我正在尝试提交“电子邮件”的值。当我测试时,如果 $this->getRequest()->getPost() 有错误,则未读取 if 块。我不能做任何其他事情,因为 if 块不起作用。所以我检查了我的表格:

public function init()
{
    $this->setName('memberdetail'); //memberdetail table from database

    /*$userid = new Zend_Form_Element_Hidden('userid'); //hide userid 
    $userid->addFilter('Int');

    $role = new Zend_Form_Element_Hidden('role');   //hide role
    $role -> setValue('Member');*/

    $email = new Zend_Form_Element_Text ('email');
    $email->setLabel('Email')
    ->setRequired(true)
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->setAttrib('COLS', '60')
    ->setAttrib('ROWS', '2')
    ->addValidator('NotEmpty')
    ->addValidator('EmailAddress');

    $submit = new Zend_Form_Element_Submit('submit');


    //remember to add the declare form elements to form
    $this->addElements(array($email, $submit)); 
}

问题出在提交按钮上吗?为什么它不返回我的“电子邮件”值?

4

1 回答 1

0

将您的代码替换为:

public function emailAction()
{

$form = new Application_Form_Email(array(
'method' => 'POST'));
$form->submit->setLabel('Send Email!');
$this->view->form = $form;

if ($this->getRequest()->isPost()) {    //check if add button is click
    echo "hi";
    $formData = $this->getRequest()->getPost('email');
    var_dump($formData);
    if ($form->isValid($formData)) { //check if form is valid 

        $emailaddress = $this->getRequest()->getPost();
        //$emailaddress = $this->getPost();
        var_dump($emailaddress);
        $db = new Application_Model_DbTable_Email();
        $db->sendEmail($emailaddress);



    } 
}
}
于 2012-08-13T08:17:37.227 回答