[TYPO3-mvc] Create multiple objects with one form using fluid

"Søren Andersen" hacksaw at zpeed.dk
Tue Mar 12 12:59:33 CET 2013


Hi Henjo,

I got it working now.

In my controller I do this:
$newBulkRegistration =
$this->objectManager->get('Namespace\Extension\Domain\Model\AllowedTypes');

AllowedTypes is a model that contain registrations only.

I populate this model with empty registration objects, one for each
allowed type.

After assigning this variable to the view, I can do this:

<f:for each="{newBulkRegistration.registrations}" as="registration"
iteration="iterator">
<f:form.hidden property="registrations.{iterator.index}.registrationDate"
value="12-3-2013" />
{registration.type.name}
<f:form.textfield property="registrations.{iterator.index}.amount"
style="width: 50px;" value="{registration.amount}" />
<f:form.textfield property="registrations.{iterator.index}.description" 
value="{registration.description}" />
<br />
</f:for>

This works as I expect it to, now I just need to build a custom validator,
to ensure the registrations are done properly.

Sincerely,
Søren Andersen

> Basically what you have to is something like this:
>
> <f:form.textfield name="items.newItem.title" />
> <f:form.textfield name="items.newItem1.title" />
> <f:form.textfield name="items.newItem2.title" />
>
> The 'newItem' part should be unique (in existing relations you'll find the
> uid there).
>
> Load the new form input in the DOM using ajax, use a viewhelper to
> generate
> unique 'newItem' thingies and there you are.
>
> You could also skip the ajax part and predefine a couple of items
> manually.
>
> That, plus a @dontverifyrequesthash annotation in your action and you are
> good to go :-)
>
> Kind regards,
>
> Henjo
>
> Problems are small because we learned how to deal with them.
> Problems are big because we need to learn how to deal with them.
>
>
> On Mon, Mar 11, 2013 at 9:51 PM, "Søren Andersen" <hacksaw at zpeed.dk>
> wrote:
>
>> Hi Henjo,
>>
>> Sounds great that you have accomplished this on several occassions.
>>
>> I worked a bit on this problem today, but I have no code to show yet.
>> Still trying to understand the correct approach conceptually.
>>
>> What I want is to build a form like this:
>> Amount of type1: <input1> [+]
>> Amount of type2: <input2> [+]
>> Amount of type3: <input3> [+]
>>
>> Each line should be made into a model of type Registration.
>>
>> Ideally the user should be able to click the plus sign, to add another
>> line of the type, if that is necessary.
>>
>> What I did today was to create a new model called AllowedTypes, which I
>> populate with the types the user can register on.
>>
>> I can iterate and output a list of types, but have no idea how to
>> structure the form in fluid. One of my issues is, if I have 3 types, I
>> somehow need to distinguish these from each other. Normally I would do
>> something like tx_myplugin_pi1[registration][1][type] and put it in a
>> hidden input, and a corresponding text input for quantity.
>>
>> Of course I can iterate the request in the controller, but if there's a
>> better way to do it I would love to know.
>>
>> Henjo, you wouldn't happen to have some public code, where you create
>> multiple objects from one form?
>>
>> Sincerely,
>> Søren Andersen
>>
>> > Hi Søren,
>> >
>> > I do not see why this is not possible... I have done it on several
>> > occasions. No need to parse it in your controllers...
>> > Maybe share a github repo so we can see some code?
>> >
>> > Kind regards,
>> >
>> > Henjo
>> >
>> > Problems are small because we learned how to deal with them.
>> > Problems are big because we need to learn how to deal with them.
>> >
>> >
>> > On Sun, Mar 10, 2013 at 9:49 AM, Daniel Lienert <daniel at lienert.cc>
>> wrote:
>> >
>> >> Hey Søren,
>> >>
>> >> As i know, there is no extbase-magic way to generate a variable
>> amount
>> >> of
>> >> objects within one "create"-call. My suggestion would be to create
>> the
>> >> objects by-hand within your create method by using the extbase
>> request
>> >> object to retrieve the array of submitted data. Validating the input
>> and
>> >> the objects manually should not be a problem, as your model seems to
>> be
>> >> very simple.
>> >>
>> >> Greetings, Daniel
>> >> --
>> >> TYPO3 related: http://daniel.lienert.cc | http://yag-gallery.de
>> >>
>> >> ______________________________**_________________
>> >> TYPO3-project-typo3v4mvc mailing list
>> >> TYPO3-project-typo3v4mvc@**lists.typo3.org<
>> TYPO3-project-typo3v4mvc at lists.typo3.org>
>> >> http://lists.typo3.org/cgi-**bin/mailman/listinfo/typo3-**
>> >> project-typo3v4mvc<
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc>
>> >>
>> > _______________________________________________
>> > TYPO3-project-typo3v4mvc mailing list
>> > TYPO3-project-typo3v4mvc at lists.typo3.org
>> > http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>> >
>>
>>
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>



More information about the TYPO3-project-typo3v4mvc mailing list