move from one action (signup) to confirm action (show the data submited) and success page Zend Framework

StackOverflow https://stackoverflow.com/questions/9927292

  •  27-05-2021
  •  | 
  •  

Question

I am a newbie to Zend and creating a simple signup form but which has many fields. So I want to create a confirm page after the user signup action.

this is how my flow goes: signup -> confirm ->success/error

My main reason for having a separate confirm form page is the data fields are so many so the user must go through to make sure they are all correctly filled.

using forms signup and confirm (with field disabled), I want to know if there is a way to pass the data from the signup form to confirm form?

Please any helpful ideas and suggestions welcomed ;)

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

Solution

When redirecting, you will lose the POST data, unless:

  1. You store it in session in signup and then read in confirmsignup
  2. You don't redirect at all. Instead, after first submit check for existence of special data in your form, it may be a random token like hash of session id etc., but not easily guessable like "confirm=1". If the token does not exist, add a hidden field with this token to your form and show it to the user again in the same action, with data filled in - this will be the confirmation phase. If you have a POST in signup again, you will receive the token and by checking it exists, you will know this is the second submit with confirmation and you may proceed with the signup. I hope I didn't overcomplicate this.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top