Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Form Template with Dynamic Number of Fields


Go to End


3 Posts   941 Views

Avatar
okotoker

Community Member, 50 Posts

3 October 2011 at 6:58am

I am trying to figure out how to render out a custom template from a form I add fields to based on an array. So for every element in the array I push a new field into the fieldset I use for the form.

What I am trying to accomplish is a cart review page with all the products added to a cart. Each item in the list has a remove button to eliminate it from the cart, a field with a number to change the amount and a update button.

So I can't just push all the fields into the form as they won't be formatted into the table I need. I can see when you render out a custom template for a form how you specify a field with a specific name should go here and so on. This won't work if I don't know the amount of fields ahead of time.

Maybe there is a better way to do this?

Thanks

Avatar
okotoker

Community Member, 50 Posts

4 October 2011 at 11:57am

I accomplished what I needed by pushing in literalfields. It seems like this wouldn't be the preferred way of handling this, so even though I got it going I would really like to hear what the better way to achieve this would be.

Thanks

Avatar
okotoker

Community Member, 50 Posts

5 October 2011 at 6:35am

So I should read things more carefully. At the bottom of the forms docs it says to use <% control Fields %>.......