[TYPO3-mvc] Multiple instances of same plugin on same page

Hendrik Nadler nadler at simplethings.de
Wed Feb 20 10:23:24 CET 2013


Hi List,

i created a little order form with extbase/fluid (TYPO3 4.5) and ran into the good old problem, that multiple instances of it on the same page lead to a... let's call it disaster. The request is mapped to each instance and so on. So I came up with the solution to assign the content element id to the form and check for it in the controller.

The form:

<f:form action="order" object="{testOrder}" name=" testOrder ">
<f:form.hidden name="formIdentifier" value="{formIdentifier}" />
...

The Controller:

/**
 * @param Tx_MyExtension_Domain_Model_TestOrder $testOrder
 * @dontvalidate $testOrder
 */
public function indexAction(Tx_MyExtension_Domain_Model_TestOrder $testOrder = null)
{
    if ($this->request->hasArgument('formIdentifier')) {
        $postedFormIdentifier = $this->request->getArgument('formIdentifier'); // the one assigned to the view
        $realFormIdentifier = $this->getFormIdentifier(); // content element uid (tt_content_uid)

        if ($postedFormIdentifier !== $realFormIdentifier) {
            $this->request->setArguments(array());
            $this->request->setErrors(array());

            $testOrder = null;
        }
    }
    
    if ($testOrder === null) {
        /** @var Tx_MyExtension_Domain_Model_TestOrder $testOrder */
        $testOrder = new Tx_MyExtension_Domain_Model_TestOrder();
    }
    
    ...
    
    $this->view->assign('formIdentifier', $this->getFormIdentifier());
    
    ...
}   

This no-tso-beautiful hack seems to work, but the error messages stack (the domain model is validated in orderAction). If you submit the second form, you get double messages, if you submit the third form, you get triple messages and so on. I use ErrorViewHelper and did not find a way to suppress the messages yet.

Tx_Fluid_ViewHelpers_Form_ErrorsViewHelper : $errors = $this->controllerContext->getRequest()->getErrors();

So, my 2 short Questions: 
a) is there a better way to solve this problem? 
b) is it possible to clear the messages in the controller, so I don't get double/triple ones?


Regards, Hendrik


More information about the TYPO3-project-typo3v4mvc mailing list