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);
}
}
}
嗨,我正在尝试提交'email'的值。当我测试时,当$ 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));
}
问题出在提交按钮上吗?为什么它不会返回我的'电子邮件'值?
答案 0 :(得分: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);
}
}
}