Validation de formulaire ignorée
bonjour,
j'ai créé une entité INDIVIDU avec une contrainte :
Code:
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 45 46 47 48 49 50
| <?php
namespace adminTools\AnnuaireBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
/**
* adminTools\AnnuaireBundle\Entity\Individu
*
* @ORM\Table(name="individu")
* @ORM\Entity(repositoryClass="adminTools\AnnuaireBundle\Entity\IndividuRepository")
*/
class Individu
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $login
*
* @ORM\Column(name="login", type="string", length=15, nullable=true)
*/
private $login;
/**
* @var string $nom
*
* @ORM\Column(name="nom", type="string", length=255, nullable=true)
*/
private $nom;
/**
* @var string $mail
*
* @ORM\Column(name="mail", type="email", length=255, nullable=true)
* @Assert\Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* )
*/
private $mail;
//////// |
un FORMULAIRE :
Handler :
Code:
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
| <?php
namespace adminTools\AnnuaireBundle\Form;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManager;
use adminTools\AnnuaireBundle\Entity\Individu;
use adminTools\AnnuaireBundle\Form\IndividuType;
use Symfony\Component\Validator\Constraints;
class IndividuHandler {
protected $form;
protected $request;
protected $em;
public function __construct(Form $form, Request $request, EntityManager $em) {
$this->form = $form;
$this->request = $request;
$this->em = $em;
}
public function process() {
if ($this->request->getMethod() == 'POST' ) {
$this->form->bindRequest($this->request);
if ($this->form->isValid()) {
return true;
}
}
return false;
}
}
?> |
Type :
Code:
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
| <?php
namespace adminTools\AnnuaireBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class IndividuType extends AbstractType {
public function buildForm (FormBuilder $builder, array $options) {
$builder
->add ('login','text')
->add ('nom', 'text')
->add ('mail', 'text')
->add ('numEtu', 'integer')
;
}
public function getName() {
return 'IndForm';
}
public function getDefaultOptions (array $options) {
return array (
'data_class' => 'adminTools\AnnuaireBundle\Entity\Individu',
);
}
}
?> |
appelé par mon controller :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public function rechercheIndAction() {
$individu = new Individu;
//création du formulaire
$form = $this->createForm(new IndividuType, $individu);
//création du gestionnaire de formulaire associé
$formHandler = new IndividuHandler($form, $this->get('request'), $this->getDoctrine()->getEntityManager());
// si pas en POST ou pas valide, on reaffiche le formulaire
if (!$formHandler->process()) {
return $this->render('adminToolsAnnuaireBundle:Annuaire:rechercheInd.html.twig', array('form'=>$form->createView()));
}
} |
tout s'affiche bien, le bind se fait, mais la validation est totalement ignorée :
je peux rentrer "sdlkfjqs" ou encore "1234" dans le champs mail, ca ne lève rien du tout, ca passe nikel....
j
j'ai testé avec un fichier validation.yml mais idem :
Code:
1 2 3 4 5 6
| adminTools\AnnuaireBundle\Entity\Individu:
properties:
mail:
- Email:
message: The email "{{ value }}" is not a valid email.
checkMX: true |