Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6761867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:14:34+00:00 2026-05-26T14:14:34+00:00

Update: since I’m not getting any answers, I’ve rewritten the entire post using a

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:14:34+00:00Added an answer on May 26, 2026 at 2:14 pm

    The reason this isn’t working as expected is because of a bug in Symfony’s stub implementation of NumberFormatter. The stub implementation will be used if you do not have the PHP intl extension installed.

    Basically, the number formatter tries to parse the value and returns false when it finds that it starts with a non-numeric character. It should set an error code which would then trigger an exception in the transformer but, since it doesn’t, the boolean false value is used and gets typecast to an integer (which is itself a bug, too). So, your “adsf” input ends up as an integer 0 and passes the type assertion.

    I found an issue report about this and I’ve sent pull requests against it for the two bugs.

    You can use those patches to fix the issue or you could work around it for now by adding a Min assertion with the limit set to 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my friend mentioned to me that since i was only using update panels on
As you may know, the wall rect will not update since its a copy
Update: Since we usually say, the situation will determine if any Design Pattern is
Update: Since this is unanswered, I'm changing the question slightly. Comments on the post
Are there any tests that compare Javascript's performance with Java's? UPDATE: Since everyone is
Important Update Since the release of MVC 2.0 Preview 1 this feature has been
UPDATE 1/31/10 : Since this thread continues to get a lot of views...I am
Since the configuration manager and update manager for eclipse 3.2 is devoid of nice
I need a quick no for DELETE/UPDATE/INSERT, since 3p reporting tool allows users to
I few days ago I update my macbook pro to snow leopard, and since

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.