[TYPO3-mvc] Multiple Checkboxes for an object in a form
Franz Koch
typo3.RemoveForMessage at elements-net.de
Tue Nov 9 12:53:20 CET 2010
Hey Christian,
> I'm trying to build a registration system for direct_mail. The task
> seems simple: records in tt_address need to be created, edited, and
> deleted. This works quite well this far.
Just curious - will it be released in TER?
> But what is driving me almost crazy for the last hours is the selection
> of categories the user wants to receive. This should be done by
> checkboxes the user might tick if he wants to receive newsletters on a
> certain topic. Working with the "property"-parameter of the
> Form_CheckboxViewHelper seems not to be an option as it seems it is only
> capable of pre-checking ONE option and the user is only capable of
> UNchecking categories, as the domain object would only return an array
> with categories it is linked to.
Of which type is your categories property? If it's a objectStorage then
the default checkboxViewHelper will deny it's service (at least for me
it does). Therefor I created a custom checkboxViewHelper that can also
deal with itterable objects (objectStorages), and with this one it's
working just fine.
...
> <f:for each="{categories}" as="category">
> <f:form.checkbox name="mailCategoriesAsArray[]" value="{category.uid}"
> checked="{x:customViewHelper(...)}" />
> </f:for>
...
> This sets an additional parameter $mailCategoriesAsArray in the create
> action. I have to assign it manually to the model but thats ok. BUT, it
> is not possible to select 2 or more categories as the HMAC will
> encounter an attack (probably as it does not expect an array).
Have you tried that approach by binding the checkbox to the property
instead?
> I tried several approaches, but none of them seem to work. Has anybody
> done something similar before? How could I solve this issue?
Of course. Just yesterday I created a form where visitors can order
brochures and the selection is done via checkboxes (my custom
checkboxViewHelper allowing objectStorages though). For me your code is
working just fine, the only difference I have is that I bound the
checkbox to the property.
<f:form.checkbox property="categories" value="{category.uid}" />
As for the preselection - you could also achieve this by creating a
empty address object in your "index" action (if none is passed) and add
preselected categories already there. But your custom viewHelper should
also be just fine.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list