0

我是 Zend 的新手,我创建了一个简单的注册表单,但它有很多字段。所以我想在用户注册操作后创建一个确认页面。

这就是我的流程:注册->确认->成功/错误

我有一个单独的确认表单页面的主要原因是数据字段太多,因此用户必须通过以确保它们都正确填写。

使用表单注册和确认(禁用字段),我想知道是否有办法从注册表单中传递数据以确认表单?

欢迎任何有用的想法和建议;)

public function signupAction()
{
    $users = new Application_Model_Users();
    $form = new Application_Form_RegistrationForm();
    $this->view->form=$form;
    if($this->getRequest()->isPost()){
        if($form->isValid($_POST)){
            $data = $form->getValues();


    //some checks before sending data to confirm page
//not sure how the data can be passed to the confirm page from here
            $this->_redirect('auth/confirmsignup');
        }
    }
}


public function confirmsignupAction()
{
    $users = new Application_Model_Users();
    $form = new Application_Form_ConfirmRegistrationForm();
    $this->view->form=$form;
    if($this->getRequest()->isPost()){
        if($form->isValid($_POST)){
            $data = $form->getValues();
            //some checks before 
            unset($data['confirmPassword']);
            $users->insert($data);
            $this->_redirect('auth/login');
        }
    }
}
4

1 回答 1

2

重定向时,您将丢失 POST 数据,除非:

  1. 您将其存储在注册中的会话中,然后在确认注册中阅读
  2. 你根本不重定向。相反,在第一次提交检查表单中是否存在特殊数据后,它可能是一个随机令牌,如会话 ID 的哈希等,但不容易猜到,如“confirm=1”。如果令牌不存在,请在您的表单中添加一个带有此令牌的隐藏字段,并在相同的操作中再次向用户显示,并填写数据 - 这将是确认阶段。如果您再次注册 POST,您将收到令牌并通过检查它是否存在,您将知道这是第二次提交确认,您可以继续注册。我希望我没有把这件事复杂化。
于 2012-03-29T15:07:36.097 回答