New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post / Redirect / Get (prg) plugin not working well, when form validation fails #7464

Closed
gargatok opened this Issue Apr 28, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@gargatok
Copy link

gargatok commented Apr 28, 2015

I encountered a bug in prg controller plugin, easily testable with zfcuser.

Try to register a new user on the /user/register page, use a 4 character password.
Result: empty form is given back, user not registered.

The form element "password" has a StringLength validator of minimum 6 characters: https://github.com/ZF-Commons/ZfcUser/blob/1.x/src/ZfcUser/Form/RegisterFilter.php#L78

In register action you can see the usage of $this->prg :
https://github.com/ZF-Commons/ZfcUser/blob/1.x/src/ZfcUser/Controller/UserController.php#L203

If I modify registerAction and remove $this->prg and go with 'traditional' approach:

        /*
        $prg = $this->prg($redirectUrl, true);

        if ($prg instanceof Response) {
            return $prg;
        } elseif ($prg === false) {
            return array(
                'registerForm' => $form,
                'enableRegistration' => $this->getOptions()->getEnableRegistration(),
                'redirect' => $redirect,
            );
        }
        */

        if ($this->getRequest()->isPost()) {
            $user = $service->register($this->getRequest()->getPost()); //$service->register has to accept objects as parameter here, by default it's array only
        }

        $redirect = isset($prg['redirect']) ? $prg['redirect'] : null;

        if (!$user) {
            return array(
                'registerForm' => $form,
                'enableRegistration' => $this->getOptions()->getEnableRegistration(),
                'redirect' => $redirect,
            );
        }

Then validation messages are returned, and previously filled email address is filled in the form.

Anything I'm missing here, and it's a Zfcuser bug? If yes, give me a clue, please.

Thank you!
All the best
Gergely

@Martin-P

This comment has been minimized.

Copy link
Contributor

Martin-P commented Apr 28, 2015

Try to register a new user on the /user/register page, use a 4 character password.
Result: empty form is given back, user not registered.

Your description sounds exactly like the one in this bug report: ZF-Commons/ZfcUser#158

When I try to register it always takes me back to the registration page. No errors are reported.

Perhaps you can open a topic on StackOverflow for this to determine what is going wrong? If it is indeed a bug you can open an issue at ZF-Commons/ZfcUser and when it actually is a bug in ZF2 you can open an issue here 👍

@gargatok

This comment has been minimized.

Copy link

gargatok commented Apr 29, 2015

@Martin-P thank you for your answer, I tried to be very careful before submitting the issue.

I made a minimalistic demonstration repository can you please check it out?
If you go on application/post you get the expected results, while application/prg gives you the buggy results.

I hope that helps, I tested this on:
PHP Version 5.5.21
Zend Server Version: 8.0.2
Zend Framework 2.4.0

https://github.com/gargatok/Zf2PrgBug

All the best,
Gergely

@gargatok

This comment has been minimized.

Copy link

gargatok commented May 4, 2015

Apparently the whole bug is related to Zend Server 8 Z-Ray.
If Z-Ray is ON, form validation error messages are lost, without it, everything seems to be fine.
I thought testing Zend Framework 2 on Zend Server is actually the best way to test...

@d3systems2

This comment has been minimized.

Copy link

d3systems2 commented Jan 7, 2019

I encountered a bug in prg controller plugin, easily testable with zfcuser.

Try to register a new user on the /user/register page, use a 4 character password.
Result: empty form is given back, user not registered.

The form element "password" has a StringLength validator of minimum 6 characters: https://github.com/ZF-Commons/ZfcUser/blob/1.x/src/ZfcUser/Form/RegisterFilter.php#L78

In register action you can see the usage of $this->prg :
https://github.com/ZF-Commons/ZfcUser/blob/1.x/src/ZfcUser/Controller/UserController.php#L203

If I modify registerAction and remove $this->prg and go with 'traditional' approach:

        /*
        $prg = $this->prg($redirectUrl, true);

        if ($prg instanceof Response) {
            return $prg;
        } elseif ($prg === false) {
            return array(
                'registerForm' => $form,
                'enableRegistration' => $this->getOptions()->getEnableRegistration(),
                'redirect' => $redirect,
            );
        }
        */

        if ($this->getRequest()->isPost()) {
            $user = $service->register($this->getRequest()->getPost()); //$service->register has to accept objects as parameter here, by default it's array only
        }

        $redirect = isset($prg['redirect']) ? $prg['redirect'] : null;

        if (!$user) {
            return array(
                'registerForm' => $form,
                'enableRegistration' => $this->getOptions()->getEnableRegistration(),
                'redirect' => $redirect,
            );
        }

Then validation messages are returned, and previously filled email address is filled in the form.

Anything I'm missing here, and it's a Zfcuser bug? If yes, give me a clue, please.

Thank you!
All the best
Gergely

Have you got any solution on it as i am struggling on the same - Please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment