Bug #88628

Redirect call on controller level is firing the action again

Added by Ronny Hauptvogel 4 months ago. Updated 3 months ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2019-06-25
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
Redirect
Complexity:
Is Regression:
Sprint Focus:

Description

I'm not really sure if this is a bug or something has changed here, but the behaviour in TYPO3 8 is not the same like in TYPO3 9.

It seems that a redirect call ($this->redirect()) on controller level will call the action again which have fired the redirect.
So if I do something like that:

class FormController extends ActionController
{
    public function showAction(): void
    {
        // nothing to do just show the form
    }

    public function redirectAction(): void
    {
        $mailData = [
            'sender' => $this->settings['senderEmail'],
            'senderName' => $this->settings['senderName'],
            'subject' => $this->settings['subject'],
            'receivers' => explode(',', $this->settings['receiverEmails']),
            'html' => '<h1>Redirect Test</h1>',
        ];

        if (MailerUtility::send($mailData)) {
            $this->redirect(
                null,
                null,
                null,
                null,
                $this->settings['redirectPageId']
            );
        }
    }
}

then the mail will be sent only once in TYPO3 8, but twice in TYPO3 9. Without the redirect call, the mail will be sent once in TYPO3 9, too. Maybe someone can tell me more about this behaviour?

Furthermore I have created a little example extension to reproduce this, which you can find in the attachment. The dependencies are set to TYPO3 9, but this example extension works in TYPO3 8, too.

  1. just install and enable the extension
  2. include the extension plugin and set some flexform data
  3. take a look at the frontend rendering of this plugin and submit the example form

redirect-test.zip (10 KB) Ronny Hauptvogel, 2019-06-25 16:14

History

#1 Updated by Philipp Faber 4 months ago

Exactly having the same problem here. I had to add a manual call like this to make it work:

header ("Location: http://". $_SERVER['HTTP_HOST']."/products");

It's a bad hack though. This might have to do sth with the PHP version?

#2 Updated by Ronny Hauptvogel 3 months ago

@Philipp

I don't think that have something to do with the PHP version, because I have used the same PHP version for both (TYPO3 8 and TYPO3 9, PHP 7.2.X).

Also available in: Atom PDF