douchui4459 2011-02-15 15:07
浏览 96
已采纳

提交表单时不显示其POST数据

I have a little experience with Zend Framework, but I like to fiddle with it until it works. But now I cannot resolve this problem.

I have a form:

<?php 
class Application_Form_Login extends Zend_Form
{

protected $notEmpty;

public function init()
{   
    // Create NotEmpty validator
    $notEmpty = new Zend_Validate_NotEmpty();

    // Configure validators for username element
    $notEmpty->setMessage('Gelieve dit veld in te vullen');

    $this->setMethod('post');

    // emailAddress
    $this->addElement('text', 'emailAddress', array(
       'filters' => array('StringTrim', 'StringToLower'),
       'required' => true,
       'validators'    => array(
            array('validator' => $notEmpty),
            ),
       'label' => 'Emailadres:'
    ));

    // password
    $this->addElement('password', 'password', array(
       'filters' => array('StringTrim'),
       'required'      => true,
       'validators'    => array(
           array('validator' => $notEmpty),
           ),
       'label' => 'Wachtwoord:'
    ));

    // submit
    $this->addElement('submit', 'submit', array(
        'ignore' => true,
        'label' => 'Inloggen'
    ));
}
}

A view:

<?= $this->form ?>

<?= $this->postdata ?>

And a AccountController:

<?php

class AccountController extends Zend_Controller_Action
{

public function init()
{
    echo 'data:'.$this->getRequest()->getPost('emailAddress');
    /* Initialize action controller here */
}

public function indexAction()
{
    $this->view->postdata = var_dump($this->getRequest()->getParams());

    $form = new Application_Form_Login();
    $request = $this->getRequest();

    if ($request->isPost()){
        // THIS POINT IS NEVER REACHED
    if ($form->isValid($request->getPost())){
            if ($this->_isValidLogin($form->getValues())){
                // Succes Redirect to the home page
                $this->_helper->redirector('index', 'home');
            }
            else // Not succes Redirect to account page
            {
                $this->_helper->redirector('index', 'account');
            }
        }

As you see I put in a comment: // THIS POINT IS NEVER REACHED. There are more functions in this controller, but those are not relevant for my problem.

Let explain it a bit more. The very strange behavior is that when I put data in my fields, $this->view->postdata = var_dump($this->getRequest()->getParams() returns no POST data. But when I put notting in the login form fields, then I see the POST data. Of course it is empty. Like this:

array
'controller' => string 'account' (length=7)
'action' => string 'index' (length=5)
'module' => string 'default' (length=7)
'emailAddress' => string '' (length=0)
'password' => string '' (length=0)
'submit' => string 'Inloggen' (length=8)

Thus, //THIS POINT IS NEVER REACHED is actually reached when putting no data in the login form fields :-)

The question is, what are I am doing wrong? Do I deal with the Zend_Controller_Request_Http in the wrong way?

If you need more info, I should give it.

  • 写回答

1条回答 默认 最新

  • doubi12138 2011-02-15 15:48
    关注

    Typing down the problem gives new insights!

    The problem is in my own code. On some point I redirect to the same page. A redirect means that the $_POST data is also cleared. Those data does - of course - not go with the new page request.

    So if someone encounter this problem with Zend Framework, namely you get no POST or GET data on submit of your form, then you need to check your redirects.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo