Bug #66588

POST Data in selectviewhelper should have higher priority than "value" value

Added by Simon Schaufelberger over 4 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Must have
Assignee:
Category:
Fluid
Target version:
Start date:
2015-04-25
Due date:
% Done:

100%

TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
easy
Is Regression:
No
Sprint Focus:

Description

given the following fluid:

<f:form.select name="myname" options="{myoptions}" value="50" />

and submitting the form with an error, the item with value 50 is always selected no matter what other value i selected before.

I would call value a default value and not a "always select" value.

A workaround would of course be to make "value" also a variable and handle the default and overwrite stuff in controller but this is really ugly!

here lies the problem: https://git.typo3.org/Packages/TYPO3.CMS.git/blob/HEAD:/typo3/sysext/fluid/Classes/ViewHelpers/Form/AbstractFormFieldViewHelper.php#l106

first the value is checked if it exists but never $value = $this->getLastSubmittedFormData(); in the case value is not an object itself.

Expected result:
POST Data should be checked BEFORE the default value is returned.

If possible please backport this bug to older TYPO3 versions!

Associated revisions

Revision 223e203f (diff)
Added by Markus Günther over 4 years ago

[BUGFIX] Submitted form data has precedence over value argument

This adjusts the behavior of all Form ViewHelpers so that any
submitted value is redisplayed even if a "value" argument has been
specified.

The issue with this, however, was that upon re-display of the form due
to property-mapping or validation errors the value argument had
precedence over the previously submitted value.

This is a breaking change if you expect the previous behavior of form
ViewHelpers always being pre-populated with the specified value
attribute / bound object property even when re-displaying the form upon
validation errors.
Besides this change deprecates
``AbstractFormFieldViewHelper::getValue()``. If you call that method in
your custom ViewHelpers you should use
``AbstractFormFieldViewHelper::getValueAttribute()`` instead and call
``AbstractFormFieldViewHelper::addAdditionalIdentityPropertiesIfNeeded()``
explicitly if the ViewHelper might be bound to (sub)entities.

The default usage of getValueAttribute() not respect the submitted form data, because not every viewhelper need
this feature. But you can enable the usage of the form data by setting the
AbstractFormFieldViewHelper::respectSubmittedDataValue to TRUE.

Change-Id: I05d9996df0a5594390ff7a005bbee7f2ceeb06bc
Resolves: #66588
Related: #34186
Releases: master
Reviewed-on: http://review.typo3.org/42298
Reviewed-by: Sascha Wilking <>
Tested-by: Sascha Wilking <>
Reviewed-by: Susanne Moog <>
Reviewed-by: Anja Leichsenring <>
Tested-by: Anja Leichsenring <>

History

#1 Updated by Simon Schaufelberger over 4 years ago

example data for options in controller:

$options = array(
    1 => one,
    50 => fifty,
    51 => fiftyone
);
$this->view->assign('myoptions', $options);

#3 Updated by Simon Schaufelberger over 4 years ago

patch idea for getValue for TYPO3 pre 6.0, below for > 6.0 ;)

if ($this->hasArgument('value')) {
    $request = $this->controllerContext->getRequest();
    if ($request instanceof Tx_Extbase_MVC_Web_Request && $request->getMethod() === 'POST') {
        $value = t3lib_div::_POST($this->arguments['name']);
    } else {
        $value = $this->arguments['value'];
    }
}

if ($this->hasArgument('value')) {
    $request = $this->controllerContext->getRequest();
    if ($request instanceof \TYPO3\CMS\Extbase\Mvc\Web\Request && $request->getMethod() === 'POST') {
        $value = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST($this->arguments['name']);
    } else {
        $value = $this->arguments['value'];
    }
}

if this looks ok, I will push it to gerrit

#4 Updated by Jan Helke over 4 years ago

  • Assignee set to Jan Helke
  • Target version set to 7.3 (Packages)
  • Sprint Focus set to On Location Sprint

#5 Updated by Gerrit Code Review over 4 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39155

#6 Updated by Gerrit Code Review over 4 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39155

#7 Updated by Gerrit Code Review over 4 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39155

#8 Updated by Benni Mack over 4 years ago

  • Target version changed from 7.3 (Packages) to 7.4 (Backend)

#9 Updated by Christian Kuhn over 4 years ago

  • Status changed from Under Review to New

The pending patch was abandoned, the approach does not work.

The issue is still valid, a good entry point is the patch that solved the same (or at least related) issue in flow: https://review.typo3.org/#/c/24794/

#10 Updated by Susanne Moog over 4 years ago

  • Complexity set to easy

#11 Updated by Simon Schaufelberger over 4 years ago

since this is merged in flow, can this be backported in this ticket?

#12 Updated by Susanne Moog over 4 years ago

  • Target version changed from 7.4 (Backend) to 7.5

#13 Updated by Gerrit Code Review over 4 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42298

#14 Updated by Markus Günther over 4 years ago

I created a small test extension...
https://github.com/markusguenther/mg_testforms

Hope that helps a bit. I need to fix the unit tests a bit.

#15 Updated by Gerrit Code Review over 4 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42298

#16 Updated by Gerrit Code Review over 4 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42298

#17 Updated by Gerrit Code Review over 4 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/42298

#18 Updated by Markus Günther over 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#19 Updated by Anja Leichsenring almost 4 years ago

  • Sprint Focus deleted (On Location Sprint)

#20 Updated by Riccardo De Contardi about 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF