I enter 123 - I get It can not be empty!
I enter 123a - I get This value is not valid.

Entity:

namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * User * * @ORM\Table(name="user") * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") */ class User { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var int * * @ORM\Column(name="intfield", type="integer") * @Assert\NotBlank( * message="Не может быть пустым!" * ) * @Assert\Type( * type="int", * message="Должно быть число!" * ) * */ private $intfield; ... 

Controller and form creation:

  /** * * @Route( * "/register" * ) * @param Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function registerAction(Request $request) { $user = new User(); $form = $this->createFormBuilder($user) ->add('intfield', TextType::class, [ 'required' => false ]) ->add('save', SubmitType::class) ->getForm(); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { //... } return $this->render('@App/register/register.html.twig', ['form' => $form->createView()] ); } 

    1 answer 1

    Change the form type to IntegerType.

      $form = $this->createFormBuilder($user) ->add('intfield', IntegerType::class, [ 'required' => false ]) 
    • She wanted a field without arrows (up / down), solved the problem with regex - Anton
    • You can change the widget and it will be without arrows. - Vadim Bondarenko
    • I forgot right away. You can create your own type of forms and it will be as text, but you can only enter int. - Vadim Bondarenko
    • Understood thanks. - Anton