Update: since I'm not getting any answers, I've rewritten the entire post using a much simpler example. Hopefully this helps expose the problem.
I'm having trouble with form validation. I can get the NotBlank() assertion to work, but Type() does not work for me. First, here's the code:
/* ...\Entity\LineItem.php */
<?php
namespace Rialto\ExperimentBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class LineItem
{
/**
* @var integer
* @Assert\NotBlank()
* @Assert\Type(type="integer")
*/
private $quantity = 0;
public function getQuantity()
{
return $this->quantity;
}
public function setQuantity($quantity)
{
$this->quantity = $quantity;
}
}
/* ...\Controller\DefaultController.php */
<?php
namespace Rialto\ExperimentBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Rialto\ExperimentBundle\Entity\LineItem;
class DefaultController extends Controller
{
public function indexAction()
{
return $this->testValidation();
}
private function testValidation()
{
$item = new LineItem();
$form = $this->createFormBuilder($item)
->add('quantity', 'integer')
->getForm();
$request = $this->getRequest();
if ( $request->getMethod() == 'POST') {
$form->bindRequest($request);
if ( $form->isValid() ) {
return new Response('Form is valid.');
}
}
return $this->render('RialtoCoreBundle:Form:basicForm.html.twig', array(
'form' => $form->createView(),
));
}
}
When I leave the input blank, I get an error message, as expected. But when I type "adsf" into the input, I see the output "Form is valid". I've tried the same thing using YAML and PHP validation. Can anyone see what I've done wrong?
Thanks, - Ian