We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



14.4k
Accepted
answer

Solved it using:

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

Thanks for watching!