我必须提交一个包含多个字段的表单(sell),其中一些来自实体,其他字段是我可以使用JQuery复制(产品)的自定义字段。 问题是在createAction中我只得到每个重复字段中的一个(最后一个)。
这是我的表单类型:
$builder
->add('montant')
->add('dateDebut', 'date', array( 'input' => 'datetime','widget' => 'single_text'))
->add('dateFin', 'date', array('input' => 'datetime', 'widget' => 'single_text'))
->add('statutVente', 'choice', array('choices' => array('Oui' => 'Oui','A finaliser' => 'A finaliser', 'A encaisser' => 'A encaisser', 'Non' => 'Non' ),'choices_as_values' => true))
->add('objet', 'choice', array('choices' => array('Entrant' => 'Entrant','Prospection' => 'Prospection', 'Renouvellement ' => 'Renouvellement' ),'choices_as_values' => true))
->add('moyenPaiement', 'choice', array('choices' => array('CB' => 'CB','Chèque' => 'Chèque', 'Virement ' => 'Virement', 'Espèces' => 'Espèces', 'Paypal' => 'Paypal', 'Autre' => 'Autre' ),'choices_as_values' => true))
->add('numeroCommande')
->add('devise', 'choice', array('choices' => array('MAD' => 'MAD','EURO' => 'EURO', 'DOLLAR ' => 'DOLLAR' ),'choices_as_values' => true))
->add('nomFacturation')
->add('tva', 'choice', array('choices' => array('OUI' => 'OUI','NON' => 'NON'),'choices_as_values' => true))
->add('reduction')
->add('adresseFacturation')
->add('cpFacturation')
->add('villeFacturation')
->add('raison')
->add('produit', 'entity', array('class' => 'VENTEBundle\\Entity\\Produit', 'mapped' => false, 'attr' => array('class'=>'add_form') ))
->add('compte', 'text', array('mapped'=> false))
->add('Sujet', null, array('mapped' => false))
->add('sujetappel', null, array('mapped' => false))
->add('Note', 'textarea', array( 'attr' => array( 'placeholder'=>""),'mapped' => false))
->add('remindertime', 'datetime', array('date_widget' => 'single_text','time_widget' => 'single_text', 'format' => 'dd-MM-yyyy HH:mm','mapped' => false,
'attr' => array( 'data-provide' => 'datepicker',
'data-date-format' => 'dd-mm-yyyy' )))
->add('dateappel', 'datetime', array('date_widget' => 'single_text','time_widget' => 'single_text', 'format' => 'dd-MM-yyyy','mapped' => false,
'attr' => array( 'data-provide' => 'datepicker',
'data-date-format' => 'dd-mm-yyyy' )))
->add('quantite', 'text', array('mapped' => false))
->add('montant_total', 'text', array('mapped' => false))
->add('nbr_personne', 'text', array('mapped' => false))
->add('duree', 'text', array('mapped' => false))
->add('description', 'textarea', array('mapped' => false));
}
这是复制字段的jquery函数:
$("#add_product").on('click', function(){
var i=1;
var original = document.getElementById('form_container_child');
var clone = original.cloneNode(true); // "deep" clone
var elements = document.getElementsByTagName('div');
clone.id = "form_container_child" + ++i;
original.parentNode.append(clone);
})
这是我的卖实体(vente)
<?php
namespace VENTEBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Vente
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="VENTEBundle\Entity\VenteRepository")
*/
class Vente
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var float
*
* @ORM\Column(name="montant", type="float")
*/
private $montant;
/**
* @var \DateTime
*
* @ORM\Column(name="date_debut", type="date")
*/
private $dateDebut;
/**
* @var \DateTime
*
* @ORM\Column(name="date_fin", type="date")
*/
private $dateFin;
/**
* @var \DateTime
*
* @ORM\Column(name="date_creation", type="datetime")
*/
private $dateCreation;
/**
* @var string
*
* @ORM\Column(name="statut_vente", type="string", length=100)
*/
private $statutVente;
/**
* @var string
*
* @ORM\Column(name="objet", type="string", length=100)
*/
private $objet;
/**
* @var string
*
* @ORM\Column(name="moyen_paiement", type="string", length=100)
*/
private $moyenPaiement;
/**
* @var string
*
* @ORM\Column(name="numero_commande", type="string", length=120)
*/
private $numeroCommande;
/**
* @var string
*
* @ORM\Column(name="devise", type="string", length=20)
*/
private $devise;
/**
* @var string
*
* @ORM\Column(name="nom_facturation", type="string", length=255)
*/
private $nomFacturation;
/**
* @var string
*
* @ORM\Column(name="tva", type="string", length=255)
*/
private $tva;
/**
* @var float
*
* @ORM\Column(name="reduction", type="float")
*/
private $reduction;
/**
* @var string
*
* @ORM\Column(name="adresse_facturation", type="string", length=500)
*/
private $adresseFacturation;
/**
* @var string
*
* @ORM\Column(name="cpfacturation", type="string", length=20)
*/
private $cpFacturation;
/**
* @var string
*
* @ORM\Column(name="ville_facturation", type="string", length=40)
*/
private $villeFacturation;
/**
* @ORM\ManyToOne(targetEntity="Raison", inversedBy="ventes")
* @ORM\JoinColumn(name="raison_id", referencedColumnName="id")
*/
private $raison;
/**
* @ORM\ManyToOne(targetEntity="COMPTEBundle\Entity\Compte", inversedBy="ventes")
* @ORM\JoinColumn(name="compte_id", referencedColumnName="id")
*/
private $compte;
/**
* @ORM\OneToMany(targetEntity="Venteproduit", mappedBy="vente")
*/
private $venteproduits;
/**
* @ORM\OneToMany(targetEntity="Ventedocument", mappedBy="vente")
*/
private $ventedocuments;
/**
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\User", inversedBy="ventes")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
/**
* Constructor
*/
public function __construct()
{
$this->venteproduits = new \Doctrine\Common\Collections\ArrayCollection();
$this->ventedocuments = new \Doctrine\Common\Collections\ArrayCollection();
$this->dateCreation = new \Datetime();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set montant
*
* @param float $montant
* @return Vente
*/
public function setMontant($montant)
{
$this->montant = $montant;
return $this;
}
/**
* Get montant
*
* @return float
*/
public function getMontant()
{
return $this->montant;
}
/**
* Set dateDebut
*
* @param \DateTime $dateDebut
* @return Vente
*/
public function setDateDebut($dateDebut)
{
$this->dateDebut = $dateDebut;
return $this;
}
/**
* Get dateDebut
*
* @return \DateTime
*/
public function getDateDebut()
{
return $this->dateDebut;
}
/**
* Set dateFin
*
* @param \DateTime $dateFin
* @return Vente
*/
public function setDateFin($dateFin)
{
$this->dateFin = $dateFin;
return $this;
}
/**
* Get dateFin
*
* @return \DateTime
*/
public function getDateFin()
{
return $this->dateFin;
}
/**
* Set dateCreation
*
* @param \DateTime $dateCreation
* @return Vente
*/
public function setDateCreation($dateCreation)
{
$this->dateCreation = $dateCreation;
return $this;
}
/**
* Get dateCreation
*
* @return \DateTime
*/
public function getDateCreation()
{
return $this->dateCreation;
}
/**
* Set statutVente
*
* @param string $statutVente
* @return Vente
*/
public function setStatutVente($statutVente)
{
$this->statutVente = $statutVente;
return $this;
}
/**
* Get statutVente
*
* @return string
*/
public function getStatutVente()
{
return $this->statutVente;
}
/**
* Set objet
*
* @param string $objet
* @return Vente
*/
public function setObjet($objet)
{
$this->objet = $objet;
return $this;
}
/**
* Get objet
*
* @return string
*/
public function getObjet()
{
return $this->objet;
}
/**
* Set moyenPaiement
*
* @param string $moyenPaiement
* @return Vente
*/
public function setMoyenPaiement($moyenPaiement)
{
$this->moyenPaiement = $moyenPaiement;
return $this;
}
/**
* Get moyenPaiement
*
* @return string
*/
public function getMoyenPaiement()
{
return $this->moyenPaiement;
}
/**
* Set numeroCommande
*
* @param string $numeroCommande
* @return Vente
*/
public function setNumeroCommande($numeroCommande)
{
$this->numeroCommande = $numeroCommande;
return $this;
}
/**
* Get numeroCommande
*
* @return string
*/
public function getNumeroCommande()
{
return $this->numeroCommande;
}
/**
* Set devise
*
* @param string $devise
* @return Vente
*/
public function setDevise($devise)
{
$this->devise = $devise;
return $this;
}
/**
* Get devise
*
* @return string
*/
public function getDevise()
{
return $this->devise;
}
/**
* Set nomFacturation
*
* @param string $nomFacturation
* @return Vente
*/
public function setNomFacturation($nomFacturation)
{
$this->nomFacturation = $nomFacturation;
return $this;
}
/**
* Get nomFacturation
*
* @return string
*/
public function getNomFacturation()
{
return $this->nomFacturation;
}
/**
* Set tva
*
* @param string $tva
* @return Vente
*/
public function setTva($tva)
{
$this->tva = $tva;
return $this;
}
/**
* Get tva
*
* @return string
*/
public function getTva()
{
return $this->tva;
}
/**
* Set reduction
*
* @param float $reduction
* @return Vente
*/
public function setReduction($reduction)
{
$this->reduction = $reduction;
return $this;
}
/**
* Get reduction
*
* @return float
*/
public function getReduction()
{
return $this->reduction;
}
/**
* Set adresseFacturation
*
* @param string $adresseFacturation
* @return Vente
*/
public function setAdresseFacturation($adresseFacturation)
{
$this->adresseFacturation = $adresseFacturation;
return $this;
}
/**
* Get adresseFacturation
*
* @return string
*/
public function getAdresseFacturation()
{
return $this->adresseFacturation;
}
/**
* Set cpFacturation
*
* @param string $cpFacturation
* @return Vente
*/
public function setCpFacturation($cpFacturation)
{
$this->cpFacturation = $cpFacturation;
return $this;
}
/**
* Get cpFacturation
*
* @return string
*/
public function getCpFacturation()
{
return $this->cpFacturation;
}
/**
* Set villeFacturation
*
* @param string $villeFacturation
* @return Vente
*/
public function setVilleFacturation($villeFacturation)
{
$this->villeFacturation = $villeFacturation;
return $this;
}
/**
* Get villeFacturation
*
* @return string
*/
public function getVilleFacturation()
{
return $this->villeFacturation;
}
/**
* Set raison
*
* @param \VENTEBundle\Entity\Raison $raison
* @return Vente
*/
public function setRaison(\VENTEBundle\Entity\Raison $raison = null)
{
$this->raison = $raison;
return $this;
}
/**
* Get raison
*
* @return \VENTEBundle\Entity\Raison
*/
public function getRaison()
{
return $this->raison;
}
/**
* Set compte
*
* @param \COMPTEBundle\Entity\Compte $compte
* @return Vente
*/
public function setCompte(\COMPTEBundle\Entity\Compte $compte = null)
{
$this->compte = $compte;
return $this;
}
/**
* Get compte
*
* @return \COMPTEBundle\Entity\Compte
*/
public function getCompte()
{
return $this->compte;
}
/**
* Add venteproduits
*
* @param \VENTEBundle\Entity\Venteproduit $venteproduits
* @return Vente
*/
public function addVenteproduit(\VENTEBundle\Entity\Venteproduit $venteproduits)
{
$this->venteproduits[] = $venteproduits;
return $this;
}
/**
* Remove venteproduits
*
* @param \VENTEBundle\Entity\Venteproduit $venteproduits
*/
public function removeVenteproduit(\VENTEBundle\Entity\Venteproduit $venteproduits)
{
$this->venteproduits->removeElement($venteproduits);
}
/**
* Get venteproduits
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getVenteproduits()
{
return $this->venteproduits;
}
/**
* Add ventedocuments
*
* @param \VENTEBundle\Entity\Ventedocument $ventedocuments
* @return Vente
*/
public function addVentedocument(\VENTEBundle\Entity\Ventedocument $ventedocuments)
{
$this->ventedocuments[] = $ventedocuments;
return $this;
}
/**
* Remove ventedocuments
*
* @param \VENTEBundle\Entity\Ventedocument $ventedocuments
*/
public function removeVentedocument(\VENTEBundle\Entity\Ventedocument $ventedocuments)
{
$this->ventedocuments->removeElement($ventedocuments);
}
/**
* Get ventedocuments
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getVentedocuments()
{
return $this->ventedocuments;
}
/**
* Set user
*
* @param \UserBundle\Entity\User $user
* @return Vente
*/
public function setUser(\UserBundle\Entity\User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
}
这是产品实体(产品)
<?php
namespace VENTEBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Venteproduit
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="VENTEBundle\Entity\VenteproduitRepository")
*/
class Venteproduit
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
*
* @ORM\Column(name="quantite", type="integer")
*/
private $quantite;
/**
* @var float
*
* @ORM\Column(name="montant_total", type="float")
*/
private $montantTotal;
/**
* @var integer
*
* @ORM\Column(name="nbr_personne", type="integer")
*/
private $nbrPersonne;
/**
* @var string
*
* @ORM\Column(name="duree", type="string", length=50)
*/
private $duree;
/**
* @var string
*
* @ORM\Column(name="description", type="string", length=500)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="Vente", inversedBy="venteproduits")
* @ORM\JoinColumn(name="vente_id", referencedColumnName="id")
*/
private $vente;
/**
* @ORM\ManyToOne(targetEntity="Produit", inversedBy="venteproduits")
* @ORM\JoinColumn(name="produit_id", referencedColumnName="id")
*/
private $produit;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set quantite
*
* @param integer $quantite
* @return Venteproduit
*/
public function setQuantite($quantite)
{
$this->quantite = $quantite;
return $this;
}
/**
* Get quantite
*
* @return integer
*/
public function getQuantite()
{
return $this->quantite;
}
/**
* Set montantTotal
*
* @param float $montantTotal
* @return Venteproduit
*/
public function setMontantTotal($montantTotal)
{
$this->montantTotal = $montantTotal;
return $this;
}
/**
* Get montantTotal
*
* @return float
*/
public function getMontantTotal()
{
return $this->montantTotal;
}
/**
* Set nbrPersonne
*
* @param integer $nbrPersonne
* @return Venteproduit
*/
public function setNbrPersonne($nbrPersonne)
{
$this->nbrPersonne = $nbrPersonne;
return $this;
}
/**
* Get nbrPersonne
*
* @return integer
*/
public function getNbrPersonne()
{
return $this->nbrPersonne;
}
/**
* Set duree
*
* @param string $duree
* @return Venteproduit
*/
public function setDuree($duree)
{
$this->duree = $duree;
return $this;
}
/**
* Get duree
*
* @return string
*/
public function getDuree()
{
return $this->duree;
}
/**
* Set description
*
* @param string $description
* @return Venteproduit
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set vente
*
* @param \VENTEBundle\Entity\Vente $vente
* @return Venteproduit
*/
public function setVente(\VENTEBundle\Entity\Vente $vente = null)
{
$this->vente = $vente;
return $this;
}
/**
* Get vente
*
* @return \VENTEBundle\Entity\Vente
*/
public function getVente()
{
return $this->vente;
}
/**
* Set produit
*
* @param \VENTEBundle\Entity\Produit $produit
* @return Venteproduit
*/
public function setProduit(\VENTEBundle\Entity\Produit $produit = null)
{
$this->produit = $produit;
return $this;
}
/**
* Get produit
*
* @return \VENTEBundle\Entity\Produit
*/
public function getProduit()
{
return $this->produit;
}
}