A
A
Andrey Zanovsky2014-03-22 10:41:10
symfony
Andrey Zanovsky, 2014-03-22 10:41:10

How to implement dynamic form in symfony?

Good afternoon.
We need to implement the following thing. There is the essence of the competition and there is the essence of prizes, for each competition there can be several prizes, depending on how many winners there will be in the competition.
And we need such a form, the user enters a number of winners into the input, let's say 5, then we need to display 5 inputs, where he will enter the names of the prizes.
How to make such a form correctly and how then to get this data and write it to the database?
The essence of the competition

/**
 * @ORM\Entity
 * @ORM\Table(name="contest")
 */
class Contest
{
/**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     * @Assert\NotBlank()
     */
    protected $name;

     /**
     * @ORM\OneToMany(targetEntity="Prize", mappedBy="contest")
     * @ORM\OrderBy({"place" = "ASC"})
     */
    protected $prizes;
}

Essence of prizes
/**
 * @ORM\Entity
 * @ORM\Table(name="prize")
 */
class Prize
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Contest", inversedBy="prizes")
     * @ORM\JoinColumn(name="contest_id", referencedColumnName="id")
     */
    protected $contest;

    /**
     * @ORM\Column(type="integer")
     */
    protected $place;

    /**
     * @ORM\Column(type="string")
     */
    protected $name;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
apasen, 2014-03-22
@andrei_z

Through collections and prototypes. The user himself will be able to add as many inputs for prizes as he wants

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question