1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
public function AjoutAction()
{
$adherent=new Adherent();
// construction du formulaire
$build= $this->createFormBuilder($adherent);
$build
->add('Nom', 'text', array('max_length' => 60, 'required' => true, 'label' => 'Nom*: ', 'trim' => true, 'read_only' => false, 'error_bubbling' => false))
->add('Prenom', 'text', array('max_length' => 60, 'required' => true, 'label' => 'Prénom*: ', 'trim' => true, 'read_only' => false, 'error_bubbling' => false))
->add('Email', 'text', array('max_length' => 100, 'required' => true, 'label' => 'Courriel*: ', 'trim' => true, 'read_only' => false, 'error_bubbling' => false))
->add('VerifEmail', 'text', array('max_length' => 100, 'required' => true, 'label' => 'Retapez le courriel*', 'trim' => true, 'read_only' => false, 'error_bubbling' => false))
->add('Adresse', 'textarea', array('required' => true, 'label' => 'Adresse*:', 'trim' => true, 'read_only' => false, 'error_bubbling' => false))
->add('TelFixe', 'text', array('max_length' => 10, 'required' => false, 'label' => 'Tél fixe:', 'trim' => true, 'read_only' => false, 'error_bubbling' => false))
->add('TelPortable', 'text', array('max_length' => 10, 'required' => false, 'label' => 'Tél portable:', 'trim' => true, 'read_only' => false, 'error_bubbling' => false))
->add('password', 'password', array('max_length' => 20, 'required' => true, 'label' => 'Mot de passe*:', 'trim' => true, 'read_only' => false, 'error_bubbling' => false))
->add('verifMotdePasse', 'password', array('max_length' => 20, 'required' => true, 'label' => 'Retapez le mot de passe*:', 'trim' => true, 'read_only' => false, 'error_bubbling' => false));
$form=$build->getForm();
// récupération du résultat du formulaire
$request = $this->get('request');
if($request->getMethod() == 'POST')
{
$form->bind($request);
if($form->isValid()) // si tout ok, on finit de remplir les attributs
{
$adherent->setUsername($adherent->getEmail());
$adherent->setCotise(true);
$adherent->setActif(true);
// et on met la bdd à jour
$em = $this->getDoctrine()->getManager();
$em->persist($adherent);
$em->flush();
// on affiche la page d'accueil de gestion des adhérents
return $this->redirect($this->generateUrl('bam_adherent_homepage'));
}
}
// si pas de validation de formulaire, on affiche les formulaire
return $this->render('BAMAdherentBundle:Default:ajout.html.twig', array('form'=>$form->createView()));
} |
Partager