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

  • SEARCH
  • Home
  • 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 8774957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:41:40+00:00 2026-06-13T18:41:40+00:00

I have a data structure where a Topic has many Questions (one to many),

  • 0

I have a data structure where a Topic has many Questions (one to many), and a Question has many Answers (one to many).

I have set up Questions as an embedded collection in the Topic form, and I have it all working 100% thanks to the cookbook entry.

When I try to develop this to embed a collection of Answer forms in the Question form then I run in to a problem.

The data-prototype attribute that contains the prototype form at the top level has the full depth of form in it, so includes the prototype for both Question and Answer. But it uses the same placeholder __name__ for each level.

<div id="topic_questions___name__">
<div class="control-group">
    <label for="topic_questions___name___questionText" class="control-label">question</label>
    <div class="form-row-errors"></div>
    <div class="controls">
        <textarea id="topic_questions___name___questionText" name="topic[questions][__name__][questionText]" required="required" class="input-block-level"></textarea>
    </div>
</div>
<div class="control-group">
    <label class="control-label">answers</label>
    <div class="controls">
        <div id="topic_questions___name___answers"     data-prototype="&lt;div class=&quot;control-group&quot;&gt;&lt;label class=&quot;control-label&quot;&gt;__name__label__&lt;/label&gt;&lt;div class=&quot;controls&quot;&gt;&lt;div id=&quot;topic_questions___name___answers___name__&quot;&gt;&lt;div class=&quot;control-group&quot;&gt;&lt;label for=&quot;topic_questions___name___answers___name___answerText&quot; class=&quot;control-label&quot;&gt;option&lt;/label&gt;&lt;div class=&quot;form-row-errors&quot;&gt;&lt;/div&gt;&lt;div class=&quot;controls&quot;&gt;&lt;input type=&quot;text&quot; id=&quot;topic_questions___name___answers___name___answerText&quot; name=&quot;topic[questions][__name__][answers][__name__][answerText]&quot; required=&quot;required&quot; maxlength=&quot;255&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;input type=&quot;hidden&quot; id=&quot;topic_questions___name___answers___name___sortOrder&quot; name=&quot;topic[questions][__name__][answers][__name__][sortOrder]&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"></div>
    </div>
</div>

You can see the really long line at the bottom, which I guess is the prototype-prototype (!) for the answer form. There is no way that I can see to only replace the question related [__name__] placeholders and not the Answer related ones.

Doing the normal

var newForm = prototype.replace(/__name__/g, collectionHolder.children().length);

when creating a real instance of a Question form of course replaces all instances of __name__ with the same value, so when the data-prototype is created for the Answer form, it has already had all the placeholders replaced.

This is what the data-prototype looks like for the Answer form, when I have clicked to add a real Question form

<div class="control-group">
<label class="control-label">1label__</label>
<div class="controls">
    <div id="topic_questions_1_answers_1">
        <div class="control-group">
            <label for="topic_questions_1_answers_1_answerText" class="control-label">option</label>
            <div class="form-row-errors"></div>
            <div class="controls">
                <input type="text" id="topic_questions_1_answers_1_answerText" name="topic[questions][1][answers][1][answerText]" required="required" maxlength="255" />
            </div>
        </div>
    </div>
</div>

As you can see, the __name__ placeholder doesnt feature at all – it was already replaced with the count for the Question form when the question form was created.

Is it possible to achieve this kind of multiple depth embedded collection with the mechanism Symfony provides?

As long as it tries to use the same placeholder for each ‘level’ then I can not see how.

  • 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-13T18:41:42+00:00Added an answer on June 13, 2026 at 6:41 pm

    Are you using at least Symfony 2.1? If so, you can change the __name__ label with the property prototype_name:

    http://symfony.com/doc/master/reference/forms/types/collection.html#prototype-name

    In your form:

    ->add('answers', 'collection', array(
        'type' => new AnswerType(),
        'allow_add' => true,
        'prototype_name' => 'another_name'
    ))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I have read through many S.O. questions regarding this topic and
I have a data structure where an entity has times stored as an int
I have the following data structure: Object _id: ca06ef84-5934-498e-9887-8a3241e713f2 answers: Object owner: 273b7291-df2b-494c-bd9b-64e71283447e Topic:
My DB have two tables - Question and Topic. To implement many-to-many relation, there
i have data structure i am passing this from server to client using data
My table have data structure like this cate_id task_id date_start date_end other 34 14
I need to have data structure, each element in which is accessible by pair
I have a data structure created using read.csv() of dimensions 130, 395. I am
I have following data structure (simplified): A giant list of the class TestClass public
I have a data structure which uses composite ids (Which I dont wish to

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.