[TYPO3-mvc] Multiple Checkboxes for an object in a form
Stephan Schreiter
sphn82 at googlemail.com
Tue Nov 9 19:59:01 CET 2010
Hey,
On Tue, 09 Nov 2010 12:21:00 +0100, Christian Zenker wrote:
> Hi.
>
> 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.
>
> 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.
>
> So I decided to give the template an additional variable with all
> available categories and checking the selected ones through a custom
> viewHelper. It looks something like this:
>
> <f:form name="address" method="post" controller="Address"
> action="create" object="{address}">
>
> <!-- fields for all other fields -->
>
> <f:for each="{categories}" as="category">
> <f:form.checkbox name="mailCategoriesAsArray[]"
value="{category.uid}"
> checked="{x:customViewHelper(...)}" /> </f:for>
> </f:form>
>
> 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).
>
> I tried several approaches, but none of them seem to work. Has anybody
> done something similar before? How could I solve this issue?
>
> Christian.
I wouldn't fiddle around with check-boxes and propose to use a multi
select box to solve the task.
quick, clean, easy:
<f:form.select id="categories" name="categories" property="categories"
options="{someModel.categories}" optionValueField="uid"
optionLabelField="title" multiple="true" size="10"
value="{formTargetModel.categories}" />
Cheers,
Stephan
More information about the TYPO3-project-typo3v4mvc
mailing list