提交表单时不显示其 POST 数据 [英] On submit the form don't display its POST data

查看:31
本文介绍了提交表单时不显示其 POST 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Zend Framework 有一点经验,但我喜欢摆弄它直到它起作用为止.但现在我无法解决这个问题.

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.

我有一个表格:

<?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'
    ));
}
}

视图:

<?= $this->form ?>

<?= $this->postdata ?>

还有一个 AccountController:

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.

让我们再解释一下.非常奇怪的行为是,当我将数据放入字段时, $this->view->postdata = var_dump($this->getRequest()->getParams() 不返回任何 POST 数据.但是当我在登录表单字段中输入 notting 时,我会看到 POST 数据.当然是空的.像这样:

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)

因此,//THIS POINT IS NEVER REACHED 实际上是在登录表单字段中没有输入数据时达到的 :-)

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

问题是,我做错了什么?我是否以错误的方式处理 Zend_Controller_Request_Http ?

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.

推荐答案

把问题写下来会带来新的见解!

Typing down the problem gives new insights!

问题出在我自己的代码中.在某些时候,我重定向到同一页面.重定向意味着 $_POST 数据也被清除.当然,这些数据与新页面请求无关.

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.

因此,如果有人使用 Zend Framework 遇到此问题,即您在提交表单时没有收到 POST 或 GET 数据,那么您需要检查您的重定向.

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.

这篇关于提交表单时不显示其 POST 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆