Exception "Array to string conversion" in form checkboxes

For a contact form I needed some NodeTypes to be available as Checkboxes. so I wrote a view helper and use it in a template as follows:

<f:layout name="Neos.Form:Field" />
<f:section name="field">
	<ul class="form-courses" id="{element.uniqueIdentifier}">
		<f:for each="{customViewHelper:resultsAnArray()}" as="course">
			<li>
			    <div>
  				    <f:form.checkbox property="{element.identifier}" multiple="1" class="{element.properties.elementClassAttribute}" value="{course.code}" errorClass="{element.properties.elementErrorClassAttribute}" />
  					<label><span class="title">{course.title}</span> <span class="code">{course.code}</span>
                      <span class="price">{course.price}</span>
                    </label>
                </div>
			</li>
		</f:for>
	</ul>
</f:section>

This seems to work fine as the form seems to be generated correctly:

<ul class="form-courses" id="courses-form-courses">
			<li>
			    <div><input class="checkbox" type="checkbox" name="--courses-form[courses][]" value="G1">...</div>
			</li>
			<li>
			    <div><input class="checkbox" type="checkbox" name="--courses-form[courses][]" value="G2">...</div>
			</li>
...
	</ul>

But when submitting the form an exception occurs:

Exception #1 in line 72 of .../.../neos/Packages/Libraries/typo3fluid/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php: Notice: Array to string conversion in .../.../neos/Packages/Libraries/typo3fluid/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php line 72

60 Neos\Flow\Error\ErrorHandler::handleError(8, "Array to string conversion", ".../.../neos/Packa…/fluid/src/Core/Parser/SyntaxTree/AbstractNode.php", 72, array|1|)
59 TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\AbstractNode::castToString(array|1|)
58 array_map(array|2|, array|5|)
57 TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\AbstractNode::evaluateChildNodes(Neos\FluidAdaptor\Core\Rendering\RenderingContext)
56 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper::renderChildren()
55 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper::TYPO3Fluid\Fluid\Core\ViewHelper\{closure}()
54 TYPO3Fluid\Fluid\ViewHelpers\ForViewHelper_Original::renderStatic(array|5|, Closure, Neos\FluidAdaptor\Core\Rendering\RenderingContext)
53 TYPO3Fluid\Fluid\ViewHelpers\ForViewHelper_Original::render()
52 call_user_func(array|2|)
51 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper::callRenderMethod()
50 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper::initializeArgumentsAndRender()
49 TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker_Original::invoke(TYPO3Fluid\Fluid\ViewHelpers\ForViewHelper, array|3|, Neos\FluidAdaptor\Core\Rendering\RenderingContext)
48 TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode_Original::evaluate(Neos\FluidAdaptor\Core\Rendering\RenderingContext)
47 TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\AbstractNode::evaluateChildNode(TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode, Neos\FluidAdaptor\Core\Rendering\RenderingContext, false)
46 TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\AbstractNode::evaluateChildNodes(Neos\FluidAdaptor\Core\Rendering\RenderingContext)
45 TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\RootNode_Original::evaluate(Neos\FluidAdaptor\Core\Rendering\RenderingContext)
44 TYPO3Fluid\Fluid\Core\Parser\ParsingState_Original::render(Neos\FluidAdaptor\Core\Rendering\RenderingContext)
43 TYPO3Fluid\Fluid\View\AbstractTemplateView::render()
42 Neos\Form\Finishers\EmailFinisher_Original::createMessage("plaintext")
41 Neos\Form\Finishers\EmailFinisher_Original::getMessages("plaintext")
40 Neos\Form\Finishers\EmailFinisher_Original::executeInternal()
39 Neos\Form\Core\Model\AbstractFinisher::execute(Neos\Form\Core\Model\FinisherContext)
38 Neos\Form\Core\Runtime\FormRuntime_Original::invokeFinishers()
37 Neos\Form\Core\Runtime\FormRuntime_Original::render()
36 Neos\Form\ViewHelpers\RenderViewHelper_Original::render()
35 call_user_func(array|2|)
34 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper::callRenderMethod()
33 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper::initializeArgumentsAndRender()
32 TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInvoker_Original::invoke("Neos\Form\ViewHelpers\RenderViewHelper", array|4|, Neos\FluidAdaptor\Core\Rendering\RenderingContext, Closure)
31 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper::renderStatic(array|4|, Closure, Neos\FluidAdaptor\Core\Rendering\RenderingContext)
30 Frontend_Node_action_show_2484ce08d006fac1a6c92a397e6b232d0fec31c0::{closure}()
29 TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper::renderStatic(array|5|, Closure, Neos\FluidAdaptor\Core\Rendering\RenderingContext)
28 Frontend_Node_action_show_2484ce08d006fac1a6c92a397e6b232d0fec31c0::render(Neos\FluidAdaptor\Core\Rendering\RenderingContext)
27 TYPO3Fluid\Fluid\View\AbstractTemplateView::render()
26 Neos\Fusion\FusionObjects\TemplateImplementation_Original::evaluate()
25 Neos\Fusion\Core\Runtime_Original::evaluateObjectOrRetrieveFromCache(Neos\Fusion\FusionObjects\TemplateImplementation, "root<Neos.Fusion:Case>/documentType<Neos.Fusion:Ma….Fusion:Matcher>/element<Neos.NodeTypes.Form:Form>", array|10|, array|5|)
24 Neos\Fusion\Core\Runtime_Original::evaluate("root<Neos.Fusion:Case>/documentType<Neos.Fusion:Ma….Fusion:Matcher>/element<Neos.NodeTypes.Form:Form>")
23 Neos\Fusion\Core\Cache\RuntimeContentCache_Original::evaluateUncached("root<Neos.Fusion:Case>/documentType<Neos.Fusion:Ma….Fusion:Matcher>/element<Neos.NodeTypes.Form:Form>", array|2|)
22 Neos\Fusion\Core\Cache\RuntimeContentCache_Original::Neos\Fusion\Core\Cache\{closure}("eval=root<Neos.Fusion:Case>/documentType<Neos.Fusi….Fusion:Matcher>/element<Neos.NodeTypes.Form:Form>", array|1|, Neos\Cache\Frontend\StringFrontend)
21 Neos\Fusion\Core\Cache\ContentCache_Original::Neos\Fusion\Core\Cache\{closure}(array|5|)
20 preg_replace_callback("/CONTENT_CACHE(?P<command>[^]+)CONTENT_CACHE(?P<data>[^]+)CONTENT_CACHE/", Closure, "HTTP/1.1 200 OK

<!DOCTYPE html><html lang="de">…/LastVisitedNode.js" async></script></body></html>", -1, NULL)
19 Neos\Fusion\Core\Cache\ContentCache_Original::replaceUncachedPlaceholders(Closure, "HTTP/1.1 200 OK

<!DOCTYPE html><html lang="de">…/LastVisitedNode.js" async></script></body></html>")
18 Neos\Fusion\Core\Cache\ContentCache_Original::getCachedSegment(Closure, "root", array|5|, false, NULL)
17 Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy::__call("getCachedSegment", array|5|)
16 Neos\Fusion\Core\Cache\RuntimeContentCache_Original::preEvaluate(array|6|, Neos\Fusion\FusionObjects\CaseImplementation)
15 Neos\Fusion\Core\Runtime_Original::evaluateObjectOrRetrieveFromCache(Neos\Fusion\FusionObjects\CaseImplementation, "root", array|12|, array|6|)
14 Neos\Fusion\Core\Runtime_Original::evaluate("root", NULL, "Exception")
13 Neos\Fusion\Core\Runtime_Original::render("root")
12 Neos\Neos\View\FusionView_Original::render()
11 Neos\Flow\Mvc\Controller\ActionController_Original::renderView()
10 Neos\Flow\Mvc\Controller\ActionController_Original::callActionMethod()
9 Neos\Flow\Mvc\Controller\ActionController_Original::processRequest(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
8 Neos\Flow\Mvc\Dispatcher_Original::initiateDispatchLoop(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
7 Neos\Flow\Mvc\Dispatcher_Original::dispatch(Neos\Flow\Mvc\ActionRequest, Neos\Flow\Mvc\ActionResponse)
6 Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy::__call("dispatch", array|2|)
5 Neos\Flow\Mvc\DispatchComponent_Original::handle(Neos\Flow\Http\Component\ComponentContext)
4 Neos\Flow\Http\Component\ComponentChain_Original::handle(Neos\Flow\Http\Component\ComponentContext)
3 Neos\Flow\Http\Component\ComponentChain_Original::handle(Neos\Flow\Http\Component\ComponentContext)
2 Neos\Flow\Http\RequestHandler::handleRequest()
1 Neos\Flow\Core\Bootstrap::run()

What is going wrong here?

Probably you access the form field as string and not interpret it as an array.

Hello Sebastian, to be honest, I’m not really aware of what I’m doing. The error seems to occur in a part of the standard way but seems to be caused by the own checkbox implementation. Due to lack of knowledge I’m not able to track the way through the NEOS form implementation. Maybe it happens within the finisher where I use the standard implementation of the Demo package:

Hello,

<f:for each="{form.formState.formValues}" as="value" key="label">
	{label}: {value}
</f:for>

Thanks

But as I told I just don’t know how to track further down. Do you have some hints for me?

Yes in the case of your checkbox {value} is now an array and not a string or number.
You have to correctly check the type of value and making the output depending on that.

I could solve the issue now by modifying the tempplate of the email finisher.
Pretty easy in the end. But before the form implementation was unable for me to track/debug and the error message was quite unspecific.

Thanks for your help.