Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:56:23+00:00 2026-06-03T20:56:23+00:00

I have a form with collection of subforms – student with different studies –

  • 0

I have a form with collection of subforms – student with different studies – relation manyToOne. I have corrent database schema and entities and form builder works well. I don’t know how to append new “study” object. I need to get html tags from somewhere in either cases – when there is at least one “study: object (clone him) or there is no such a one.

Let’s assume that study object has 2 fields: name and year. If for a student there is such a record (object) it’s first input in generated form has name “student[study][0][name]”. And is surrounded by . When I click “Add new study” button I want to duplicate this surrounding div and change id’s and name’s of html form elements respectively. Is there ready library or method to use?

But there may happen there is no study records so far. So I need to get form from server through ajax call. Unfortunately returned form has inputs with names like “study[name]”. Is it possible to render this form similar to first case – I mean “student[study][0][name]”. But i’d like to avoid manually generate twig template for form – I prefer

{{ form_widget(form) }}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:56:25+00:00Added an answer on June 3, 2026 at 8:56 pm

    You should be dealing with data-prototype rather than issuing separate AJAX request. The whole concept of adding/removing subform items is described here:

    http://symfony.com/doc/current/reference/forms/types/collection.html#adding-and-removing-items

    Obviously, you will need to some JS (jQuery is highly recommended) in order to replicate subform fields.

    You should note, however, that data-prototype behaves differently when you initially have empty or non-empty collection. At least I have encountered this weird behavior. As far as I remember, in first your when you say {{ form_rest(form) }} additional DIV is appended with data-prototype attribute consisting of form’s HTML. In second case actual HTML (not as an attribute) is appended with ID attribute “form_name_$$name$$” where you need to replace $$name$$ with proper index.

    Now, you really should take a look – maybe all this has been fixed in some recent versions but I can’t be sure…

    Hope this helps a bit…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form where users can modify a collection of objects using a
I have a collection of the form: map<key, list<object> > I only ever insert
I have: form.input :duration, as: select, collection: {} I need: <option value= data-price=XXX></option> Rails
I have a form with a collection of Html and ASP Server Controls. Im
I have a form with two different UserControls - one that contains a Telerik
I have a form which fills some objects of a Collection. I had the
I have a Collection Form class MyCollectionForm extends sfForm { public function configure() {
I'm using ASP.NET MVC, and I have a widget within my form collection on
In my form I have: <%= f.association :virksomhed, :collection => Virksomhed.all(:order => 'navn'), :prompt
I currently have a method in my controller which accepts a form collection, saves

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.