Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Insert POST values after createAction

Hi,

I'd like to seperate index from create actions. But the POST data doesn't get inserted when the form isn't valid. Short version of my code:

public function indexAction() {
     // Set form
    $this->view->registrationForm = new RegistrationForm;
}

public function createAction() {
    $registrationForm = new RegistrationForm;

    // Check if post
    if ($this->request->isPost()) {
        if (!$registrationForm->isValid($this->request->getPost())) {
            foreach ($registrationForm->getMessages() as $message) {
                $this->flash->error($message->getMessage());
            }
            $this->response->redirect('/nutzer/registrierung/');
        } else {
            // save
        }
    }
}

The error messages appear but the POST data isn't populated.



4.3k
Accepted
answer

Solved it using:

$this->dispatcher->forward(['action' => 'index']);

Thanks for watching!