Berisol
Berisol

Reputation: 77

Submit array from Fluid-Template to Controller with f:form viewhelper

I am currently writing an Extbase Extension with a backend module. I have assigned an array to the template of my backend module. Now I am trying to submit that array back to my crontroller action "pageGenerator" with inputs of the form in the template. Here is the code from my controller and template:

Controller:

public function listAction()
{
    $array = [
        '1' => '',
        '2' => '',
        '3' => ''
    ];
    $this->view->assign('array', $array);
    $this->view->setTemplatePathAndFilename('EXT:bm_test/Resources/Private/Templates/template.html');

}
public function pageGeneratorAction(array $array=null){}

Fluid-Template:

 <div align="center">
  <f:form method="post" controller="DomainModel" action="pageGenerator" 
     name="array" object="{array}" >
    <input type="text" name="array[1]">
    <input type="text" name="array[2]">
    <input type="text" name="array[3]"> 
    <f:form.submit value="Submit" />
</f:form>
 </div>

The problem is that the array is null no matter what I type into the textfields.When i remove the "=null" from the pageGenerator action i get the following Error:

Too few arguments to function Bmt\BmTest\Controller\DomainModelController::pageGeneratorAction(), 0 passed and exactly 1 expected

So it seems like that the array isn't submitted. Does anyone know what am I doing wrong here? Thanks in advance for your help.

Upvotes: 0

Views: 899

Answers (1)

Marco De Felice
Marco De Felice

Reputation: 11

have you tried to insert the assign variable after setTemplatePathAndFilename ? Becouse in typo3 if the template haven't the same name of the Action you need first inizialize them and after return the view with assigned variable example

$this->view->setTemplatePathAndFilename('EXT:bm_test/Resources/Private/Templates/template.html');
$this->view->assign('array', $array);
return $this->view->render();

Upvotes: 1

Related Questions