Project

General

Profile

Actions

Bug #80341

closed

wrong hiiden parts in the f:form -Viewhelepr

Added by Dieter Porth over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
-
Target version:
-
Start date:
2017-03-18
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

TYPO3-Version 8.6.1
last update 6. march 2017 (NOT dev-Version)

Destination
I want to call a not-default controller and a not default Action in a my plugin.
Try
I use the viewhelper f:form in my fluid-template with the needed parameters.

           <f:form method="post" 
                    controller="Bubble" 
                    action="{actionType}{actionFields}{actionParent}" 
                    pageType="{f:if(condition:'{loadtype}=={settings.frontendEditing.ajaxLoadType}',then:'{settings.frontendEditing.ajaxTypeNum}',else:'{settings.frontendEditing.redirectTypeNum}')}" 
                    arguments="{parent:parent}" 
                    additionalParams="{switcher:plugIn}" 
                    pluginName="{plugIn}" 
                    name="bubble" 
                    object="{bubble}" 
                    id="{ridForm}" 
                    class="[ js-form-fe ]" 
                    additionalAttributes="{ data-error:         '{f:translate(key:\'LLL:EXT:positioner/Resources/Private/Language/locallang_backend.xlf:tx_positioner_domain_model_bubble.update.error\')} {infoText.error}',
                                            data-success:       '{f:translate(key:\'LLL:EXT:positioner/Resources/Private/Language/locallang_backend.xlf:tx_positioner_domain_model_bubble.update.success\')} {infoText.success}',
                                            data-action-reload: '{f:translate(key:\'LLL:EXT:positioner/Resources/Private/Language/locallang_backend.xlf:tx_positioner_domain_model_bubble.question.{actionType}\')}',
                                            data-actiontype:    '{actionType}',
                                            data-type:          menuDataReaction
                                        }" 
            >


The Veiwhelper redirect me to the default-Action of my controller.

Reason
The viewhelper don't respect its parameter. It build the wrong parameter in the hidden @request-Part of the form.
The wrong result were for example:

<input name="tx_positioner_cartoon[__referrer][@extension]" value="Positioner" type="hidden">
<input name="tx_positioner_cartoon[__referrer][@vendor]" value="Porth" type="hidden">
<input name="tx_positioner_cartoon[__referrer][@controller]" value="Cartoon" type="hidden">
<input name="tx_positioner_cartoon[__referrer][@action]" value="detail" type="hidden">
<input name="tx_positioner_cartoon[__referrer][arguments]" value="YTowOnt9fb66287f032eff31613853e997bfe87205fd0194" type="hidden">
<input name="tx_positioner_cartoon[__referrer][@request]" value="a:4:{s:10:"@extension";s:10:"Positioner";s:11:"@controller";s:7:"Cartoon";s:7:"@action";s:6:"detail";s:7:"@vendor";s:5:"Porth";}d29f832dadf2269189da2e1c49cbe84d37547681" type="hidden">
<input name="tx_positioner_cartoon[__trustedProperties]" value="a:2:{s:6:"bubble";a:3:{s:4:"name";i:1;s:7:"opacity";i:1;s:12:"themeclasses";i:1;}s:10:"cancelForm";i:1;}11c64f4a232105b5272d97afe197564ae9f9b9e6" type="hidden">

Solution
I defined myown form-viewhelper, which replaced one mistaken protected method in the following way

class FormViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper
{

    /**
     * Renders hidden form fields for referrer information about
     * the current controller and action.
     *
     * @return string Hidden fields with referrer information
     */
    protected function renderHiddenReferrerFields()
    {
        $request = $this->renderingContext->getControllerContext()->getRequest();
        $extensionName = (empty($this->arguments['extensionName']) || is_null($this->arguments['extensionName'])) ?
            $request->getControllerExtensionName():
            $this->arguments['extensionName'];
        $vendorName = (empty($this->arguments['vendorName']) || is_null($this->arguments['vendorName'])) ?
            $request->getControllerVendorName():
            $this->arguments['vendorName'];
        $controllerName = (empty($this->arguments['controller']) || is_null($this->arguments['controller'])) ?
            $request->getControllerName():
            $this->arguments['controller'];
        $actionName = (empty($this->arguments['action']) || is_null($this->arguments['action'])) ?
            $request->getControllerActionName():
            $this->arguments['action'];
        $actionRequest = [
            '@extension' => $extensionName,
            '@controller' => $controllerName,
            '@action' => $actionName,
        ];
        $arguments= ((count($this->arguments['arguments']) <= 0)? $request->getArguments() : $this->arguments['arguments']);

        $result = LF;
        $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@extension]') . '" value="' . $extensionName . '" />' . LF;
        if ($vendorName !== null) {
            $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@vendor]') . '" value="' . $vendorName . '" />' . LF;
            $actionRequest['@vendor'] = $vendorName;
        }
        $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@controller]') . '" value="' . $controllerName . '" />' . LF;
        $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@action]') . '" value="' . $actionName . '" />' . LF;
        $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[arguments]') . '" value="' . htmlspecialchars($this->hashService->appendHmac(base64_encode(serialize($arguments)))) . '" />' . LF;
        $result .= '<input type="hidden" name="' . $this->prefixFieldName('__referrer[@request]') . '" value="' . htmlspecialchars($this->hashService->appendHmac(serialize($actionRequest))) . '" />' . LF;

        return $result;
    }

}


The method now respect the entries of the form-viewhelper. The generated form has the needed hidden fields.
<input name="tx_positioner_cartoon[__referrer][@extension]" value="Positioner" type="hidden">
<input name="tx_positioner_cartoon[__referrer][@vendor]" value="Porth" type="hidden">
<input name="tx_positioner_cartoon[__referrer][@controller]" value="Bubble" type="hidden">
<input name="tx_positioner_cartoon[__referrer][@action]" value="createbubblespeech" type="hidden">
<input name="tx_positioner_cartoon[__referrer][arguments]" value="YToxOntzOjY6InBhcmVudCI7TzozNjoiUG9ydGhcUG9zaXRpb25lclxEb21haW5cTW9kZWxcU3BlZWNoIjoxNDp7czo3OiIAKgB0ZXh0IjtzOjExOiJUZXh0IFNwZWVjaCI7czoxMjoiACoAZGltZW5zaW9uIjtOO3M6MTE6IgAqAHBvc2l0aW9uIjtOO3M6MTE6IgAqAHJvdGF0aW9uIjtOO3M6OToiACoAYnViYmxlIjtOO3M6MTI6IgAqAHJlc291cmNlcyI7TjtzOjE1OiIAKgB0aGVtZWNsYXNzZXMiO3M6MDoiIjtzOjY6IgAqAHVpZCI7aToxO3M6MTY6IgAqAF9sb2NhbGl6ZWRVaWQiO2k6MTtzOjE1OiIAKgBfbGFuZ3VhZ2VVaWQiO2k6MDtzOjE2OiIAKgBfdmVyc2lvbmVkVWlkIjtpOjE7czo2OiIAKgBwaWQiO2k6NjtzOjYxOiIAVFlQTzNcQ01TXEV4dGJhc2VcRG9tYWluT2JqZWN0XEFic3RyYWN0RG9tYWluT2JqZWN0AF9pc0Nsb25lIjtiOjA7czo2OToiAFRZUE8zXENNU1xFeHRiYXNlXERvbWFpbk9iamVjdFxBYnN0cmFjdERvbWFpbk9iamVjdABfY2xlYW5Qcm9wZXJ0aWVzIjthOjk6e3M6NDoidGV4dCI7czoxMToiVGV4dCBTcGVlY2giO3M6OToiZGltZW5zaW9uIjtOO3M6ODoicG9zaXRpb24iO047czo4OiJyb3RhdGlvbiI7TjtzOjY6ImJ1YmJsZSI7TjtzOjk6InJlc291cmNlcyI7TjtzOjEyOiJ0aGVtZWNsYXNzZXMiO3M6MDoiIjtzOjM6InVpZCI7aToxO3M6MzoicGlkIjtpOjY7fX19ebadffc114f86f4970dad019af88ac0ad9464424" type="hidden">
<input name="tx_positioner_cartoon[__referrer][@request]" value="a:4:{s:10:"@extension";s:10:"Positioner";s:11:"@controller";s:6:"Bubble";s:7:"@action";s:18:"createbubblespeech";s:7:"@vendor";s:5:"Porth";}fdf02d94cb91a498012479be4cb3ea42906fcf9a" type="hidden">
<input name="tx_positioner_cartoon[__trustedProperties]" value="a:2:{s:6:"bubble";a:3:{s:4:"name";i:1;s:7:"opacity";i:1;s:12:"themeclasses";i:1;}s:10:"cancelForm";i:1;}11c64f4a232105b5272d97afe197564ae9f9b9e6" type="hidden">

remark parameter actionUri
I tried to use the f:uri.action-viewhelper to define the argument of actionUri. It don't work. I think, it make the same mistake as the f:form-viewhelper; BUT I havn't analysed the way of problem in detail.

second remark
The problem with the buggy f:form-viewhelper seems to be old. I found a two year old question in stackoverflow.

http://stackoverflow.com/questions/28998206/how-to-set-referrer-of-a-form-to-another-action-and-controller


Related issues 2 (1 open1 closed)

Related to TYPO3 Core - Feature #77025: f:form: Disable referrer informationNew2016-07-11

Actions
Is duplicate of TYPO3 Core - Feature #65717: Extbase/Fluid: Add possibility to set an "error action" for forms and links in MvCClosed2015-03-13

Actions
Actions

Also available in: Atom PDF