Search code examples
typo3fluid

TYPO3 f:form with additional arguments, where submit not update the arguments


I am using TYPO3 10.4.15 My edit view:

f:section name="content">
    <h1>Edit Album</h1>
    <f:flashMessages />
    <f:render partial="FormErrors" />
    <f:form id='fNew' action="update" name="album" object="{album}" arguments="{mode:mode, disc:disc}" >
    <f:render partial="Album/FormFields" arguments="{album:album, disc:disc}" />
    <f:form.submit value="Save" />
    </f:form>
</f:section>
</html>

This is the relevant part of the partial formfields.html:

    <f:if condition='{disc}'>
    <input type='text' name="disc[0][name][]" />
    </f:if>

The error_log with the disc structure looks:

 Update-Disc: array (
  0 => 
  array (
    'name' => '',
    'trackNum' => '1',
    'track' => 
    array (
      0 => 
          array (
            'title' => '',
            'duration' => '0',
            'composer' => '',
            'texter' => '',
            'musicFile' => '',
            'imageFile' => '',
          ),
        ),
      ),
    ) 

And this is the "updateAction" part of the controller

/**
 * action update
 * 
 * @param \HGA\Album\Domain\Model\Album $album
 * @param string $mode
 * @param array $disc
 * @return string|object|null|void
 */
public function updateAction(\HGA\Album\Domain\Model\Album $album, $mode, $disc)
{
    error_log("Update-Disc: " . var_export($disc, true) . " Mode: " . $mode, 0);
    if ($mode == 'tracks') {
       $this->editAction($album, $mode, $disc);
    }
    error_log("Update: " . var_export($album, true) . " Mode: " . $mode, 0);
    $this->addFlashMessage('The object was updated. Please be aware that this action is publicly accessible unless you implement an access check. See https://docs.typo3.org/typo3cms/extensions/extension_builder/User/Index.html', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::WARNING);
    $this->albumRepository->update($album);
    $this->redirect('list');
}

If I write something into the text input field and execute submit, I get the error_log you can see above. The value I have typed in the input field is missing. It is only the array, as I have send it to the view. The mode string will be transmitted correctly, but with the disc array is maybe something wrong!

The disc array is more complex, but I made it simple, because I need to understand how it works in general. I also need this additional disc array and can not doing it with the album object!

Thanks in advance for your help.


Solution

  • You are ignoring your plugin's namespace in combination with misinterpretation of f:form arguments.

    Each field for your plugin has a prefix like tx_hgaalbum... followed by your property's name in square brackets. So the fieldname for disc should look like tx_hgaalbum...[disc]. Have a look into the HTML code and see which names are generated for the other properties.

    The second problem is using the arguments in the form-ViewHelper. This will only add the arguments to the action URI of your form. That's why you're getting your initial values for disc.