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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:28:02+00:00 2026-06-14T11:28:02+00:00

i have problem with binding data from a form to database, I have a

  • 0

i have problem with binding data from a form to database, I have a form with test name and it’s categories, when i want to add values from forms to database it only binds the name of the test and only ONE name of the category, how can i make to bind other categories to database …:
My controller:

public function createAction()
{
    $success = 0;
    $name = $this->getRequest()->get('name');

    if( !empty($name) )
    {
        $test = new Test();
        $test->setName($this->getRequest()->get('name'));

        $em = $this->getDoctrine()->getManager();
        $em->persist($test);
        $em->flush();

        $success = 'Test '.$test->getName().' was created';
    }
    else
    {
        $success = 'Test name can not be empty';
    }

    $category = $this->getRequest()->get('category-new');

    if( !empty($category))
    {

        $categoryName = new Category();
        $categoryName->setName($this->getRequest()->get('category-new'));


        $em = $this->getDoctrine()->getManager();
        $em->persist($categoryName);
        $em->flush();

        $success = 'Category '.$categoryName->getName().' was created';
      }

    else
    {
        $success = 'Category name can not be empty';
    }

    return $this->redirect($this->generateUrl('test.new'));
}

My twig file:

 extends '::base.html.twig' %}

  {% block stylesheets %}
   {{ parent() }}
  <link rel="stylesheet" href="{{ asset('bundles/ladelaodesktester/css/new.css') }}" 
   type="text/css" media="all">

<link rel="stylesheet" href="{{ asset('bundles/ladelaodesktester/css/colorpicker.css') 
    }}" type="text/css" media="all">
<link rel="stylesheet" href="{{ asset('bundles/ladelaodesktester/css/layout.css') }}" 
  type="text/css" media="all">
  {% endblock %}

    {% block body %}
     <ul id="breadcrumb">
  <li><a href="{{path('homepage')}}" title="Home"><img src="{{ 

  asset('bundles/ladelaodesktester/images/home.png') }}" alt="Home" class="home" /></a>
  </li>
   <li><a href="{{path('test.new')}}" title="New"> New test </a></li>
   <li> Please add data to new test </li>
    </ul>
   {#<div class="wrap">#}
   <div class="new-test">
   <h2>New test </h2>
    <form action="{{ path('test.create') }}" method="post">
        Test name: <input type="text" name="name"/><br>

         Category 1  <input class="color {valueElement:'myValue'}" type="text" 
         name="category-new"><br>
        Category 2  <input class="color {valueElement:'myValue1'}" type="text" 
        name="category-new"><br>
        Category 3  <input class="color {valueElement:'myValue2'}" type="text" 
        name="category-new"><br>
        Category 4  <input class="color {valueElement:'myValue3'}" type="text" 
         name="category-new"><br>
        Category 5  <input class="color {valueElement:'myValue4'}" type="text" 
        name="category-new"><br>


        <input type="submit" value="Add">
        </form>
       </div>
     <table class="test-list">
       <caption></caption>
        <tbody>
      <tr>
          <th>Test name</th>
        <th># questions</th>
        <th># passed</th>
        <th># action</th>
    </tr>
    {% for test in tests %}
    <tr>
        <td>
           {{ test.name }}
        </td>
        <td>
           {{ test.countquestions }}
        </td>
        <td>
            {{ test.countresults }}
        </td>
        <td>
            <a href="{{ path('test.show', { 'slug': test.slug }) }}">analyze</a>|
            <a href="">new result</a> |
            <a href="{{ path('edit.test', { 'slug': test.slug }) }}">edit </a>
        </td>
    </tr>
    {% endfor %}
    </tbody>
  </table>
   {#</div>#}
{% endblock %}
{% block javascripts %}
  {{ parent() }}
  <script src="{{ asset('bundles/ladelaodesktester/js/new.js') }}" 
  type="text/javascript"></script>
<script src="{{ asset('bundles/ladelaodesktester/js/jscolor.js') }}" 
 type="text/javascript"></script>
{% endblock %}

my entity of category:

class Category
{
/**
 * @var integer $id
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string $name
 *
 * @ORM\Column(name="name", type="string", length=255)
 */
private $name;

/**
 * @var string $color
 *
 * @ORM\Column(name="color", type="string", length=255)
 */
private $color;

public function __construct()
{
  $this->color = '255,255,0'; // default color for category
}

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

/**
 * Set name
 *
 * @param string $name
 * @return Category
 */
public function setName($name)
{
    $this->name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string
 */
public function getName()
{
    return $this->name;
}

/**
 * Set color
 *
 * @param string $color
 * @return Category
 */
public function setColor($color)
{
    $this->color = $color;

    return $this;
}

/**
 * Get color
 *
 * @return string
 */
public function getColor()
{
    return $this->color;
 }

}
  • 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-14T11:28:03+00:00Added an answer on June 14, 2026 at 11:28 am

    Change the input name to: “category-new[]” to make it an array.

    in the controller:

    $categories = $this->getRequest()->get('category-new');
    foreach($categories as $category) {
        $categoryName = new Category();
        $categoryName->setName($category);
    
    
        $em = $this->getDoctrine()->getManager();
        $em->persist($categoryName);
    }
    $em->flush();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a little problem. I'm using data binding to retrieve data from
I have a problem using HtmlDataTable for viewing data from database. When I create
I have a problem in binding JSON data to KENDO Pie Chart. I have
In my MVC application I have a problem with passing data from view to
I have data comming back from web service in the form of a ObservableCollection<string>
I have problem with adding image to DGV cell after data binding. this is
I have an issue with model binding a checkbox from a form to an
I have some problem converting my data from an plist to objects. The plist
i have problem in data binding in expandable list view. here i use ArrayList<ExpandListGroup>
i have a datagrid that load the data from my database. in my datagrid,

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.