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 8515557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:10:51+00:00 2026-06-11T05:10:51+00:00

I create a simple form with multiple rows: Controller: public function indexAction() { $repository

  • 0

I create a simple form with multiple rows:

Controller:

public function indexAction() 
{
    $repository = $this->getDoctrine()->getRepository('MyBundle:Product');
    $products = $repository->findAll();

    foreach ($products as $product) {
        $forms[] = $this->createForm(new ProductType, $product)->createView();
    }

    return $this->render('MBundle:Default:index.html.twig', array('form' => $forms);        

}

I render this in a twig:

<form action="{{ path('_submit') }}" method="post">
{% for key, formData in forms %}
    {{ form_row(formData.id) }}
    {{ form_row(formData.name) }}
    {{ form_row(formData.nameEnglish) }}
    <br clear="all" />
{% endfor %}
</form>

When i submit form each of my input field set has the same name attributes and i get only the last one. How to grab all the rows and validate them in my submitAction() controller? Each input needs to have unique name, right? … and perhaps i need to set somehow name=”something[name][]” but how to do it?

  • 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-11T05:10:53+00:00Added an answer on June 11, 2026 at 5:10 am

    Ok Cerad was right with his comment and we have to use collection for this. It may sound like a nonsense at first but it kinda is right. It took me a while to get head around it.

    So i had to create a ProductsType which is an arrayCollection and inserts each Product. (just like in documentation with Task and tags)

    I used that:

    $repository = $this->getDoctrine()->getRepository('ExampleBundle:Product');
    $products = $repository->findAll();
    
    $productCollection = new Products;
    
    foreach ($products as $product) {
        $productCollection->getProducts()->add($product);
    }
    
    $collection = $this->createForm(new ProductsType, $productCollection);
    
    return $this->render('ExampleBundle:Default:index.html.twig', array(
        'collection' => $collection->createView()
            ));
    

    Then in twig i do:

    <div class="products">
        {% for product in collection.products %}
            {{ form_row(product.id) }}
            {{ form_row(product.name) }}
            {{ form_row(product.description) }}
            <br clear="all" />
        {% endfor %}
    </div>    
    

    Job done.

    And even you can apply themes to each row by this:

    {% block _productsType_products_entry_name_row %}
        <div class="yourDivName">{{ block('form_widget') }}</div>
    {% endblock %}
    {% block _productsType_products_entry_description_row %}
        <div class="yourDivDescription">{{ block('form_widget') }}</div>
    {% endblock %}
    

    Cool stuff!

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

Sidebar

Related Questions

i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I'm trying to create a simple form with two different submit buttons: one which
I am trying to create a simple GUI form which has only 2 elements
In my Java app I am trying to create a very simple form with
I want to create a simple user registration form with First / Last name,
I am trying to create what I feel is a very simple form submission
Im trying to create a simple input box with form validation, but im not
I'm trying to create a simple file upload form for my website. I'm using
Let's consider this scenario: a freshly create windows form application in which I created
I'm hoping to create a fairly simple 'filter by multiple checkbox' search tool for

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.