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 8289567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:32:16+00:00 2026-06-08T12:32:16+00:00

I need help about validation forms without entity but with form class. My problem

  • 0

I need help about validation forms without entity but with form class. My problem is the collection constraint in my form class in the override method getDefaultOoptions. It doesn’t take this collection into account when I bind the form in my controller.

This is my class form

    namespace Projet\TicketBundle\Form;

use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Collection;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class TicketPackAndAppType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('total', 'text' ,array('label' => 'Total de la commande  ',     'read_only' => true))


            ->add('address_delivery', 'entity' , array('class' => 'TacTill\CustomerBundle\Entity\Address',
                  'property' => 'address',
                  'required' => false,
                  'label' => 'Adresse de livraison  ',
                  'required' => false
                 ))
            ->add('address_invoice', 'entity' , array('class' => 'TacTill\CustomerBundle\Entity\Address',
                  'property' => 'address',
                  'required' => false,
                  'label' => 'Adresse de facturaton  ',
                  'required' => false
                 ))


            ->add('color', 'choice', array(
                'choices' => array(
                    'B' => 'Noir', 
                    'W' => 'Blanc'),
                'required' => true,
                "property_path" => false,
                'expanded' => true,
                'multiple' => false
            ))

            ->add('model', 'choice', array(
                'choices' => array(
                    'iPadDeux16Gowifi' => '16 Go Wifi', 
                    'iPadDeux16Gowifi3G' => '16 Go Wifi et 3G', 
                    'iPadNew16Gowifi' => '16GoWifi', 
                    'iPadNew32Gowifi' => '32 Go Wifi',
                    'iPadNew64Gowifi' => '64 Go Wifi',
                    'iPadNew16Gowifi4G' => '16 Go Wifi et 4G',
                    'iPadNew32Gowifi4G' => '32 Go Wifi et 4G',
                    'iPadNew64Gowifi4G' => '64 Go Wifi et 4G'
                    ),
                'required' => true,
                "property_path" => false,
                'expanded' => true,
                'multiple' => false
            ))       

            ->add('stand', 'choice', array(
                'choices' => array(
                    'standsecurity' => 'Sécurité', 
                    'standdesign' => 'Design',
                    'standmobility' => 'Mobilité'
                    ),
                'required' => true,
                "property_path" => false,
                'expanded' => true,
                'multiple' => false
            )) 

            ->add('printer', 'choice', array(
                'choices' => array(
                    'printerB' => 'Noire', 
                    'printerW' => 'Blanche'
                    ),
                'required' => true,
                "property_path" => false,
                'expanded' => true,
                'multiple' => false
            ))  

            ->add('cashDrawer', 'choice', array(
                'choices' => array(
                    'cashDrawerG' => 'Graphite', 
                    'cashDrawerP' => 'Perle'
                    ),
                'required' => true,
                "property_path" => false,
                'expanded' => true,
                'multiple' => false
            )) 

            ->add('app', 'choice', array(
                'choices' => array(
                    'appSmall' => 'S\'abonner à TacTill', 
                    'noApp' => 'Télécharger l\'application plus tard'
                    ),
                'required' => true,
                "property_path" => false,
                'expanded' => true,
                'multiple' => false
            ))                  
        ;                      

    }


    public function getName()
    {
        return 'ticket_packandapptype';
    }

    public function getDefaultOptions(array $options)
    {
        $collectionConstraint = new Collection(array(
                'color' => new NotBlank(array('message' => 'Champ vide')),
                'model' => new NotBlank(array('message' => 'Champ vide')),
                'stand' => new NotBlank(array('message' => 'Champ vide')),
                'printer' => new NotBlank(array('message' => 'Champ vide')),
                'cashDrawer' => new NotBlank(array('message' => 'Champ vide')),
                'app' => new NotBlank(array('message' => 'Champ vide')),
        ));

        return array('validation_constraint' => $collectionConstraint);
    }
}

In my controller

public function createOrderAction()
{

    $em = $this->getDoctrine()->getEntityManager();

    $requestInArray = $this->getRequest()->request->get('ticket_packandapptype'); 

    $request = $this->getRequest();
    $form    = $this->createForm(new TicketPackAndAppType());

    if ($request->getMethod() == 'POST') {

        $form->bind($requestInArray);



        $stand = $requestInArray['stand'];
        $printer = $requestInArray['printer'];
        $cashDrawer = $requestInArray['cashDrawer'];
        $app = $requestInArray['app'];
  }
}   

I have also test with bindRequest and that is the same problem.

I follow the Validation without class but i don’t where is the mistake.
When i have done the without form class the collection constraints works well.

If you have any idea, explain to me. Thank you

  • 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-06-08T12:32:17+00:00Added an answer on June 8, 2026 at 12:32 pm

    You should do smth like this:

    if ($request->getMethod() == 'POST') {
    
        $form->bindRequest($request);
        if ($form->isValid()) {
            //do your actions with form values
        } else {
           //return form with error messages
           //or do smth else...
        }
    

    }

    When you call isValid() Symfony tries to checks you daya with your constraint…

    Also you should get your data through form:

    $data = $form->get('your_field_name')->getData();
    

    Of course you should do it after binding form from request…

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

Sidebar

Related Questions

Not exactly about programming, but I need help with this. I'm running a development
I need some help with PHP Class. I have limited knowledge about how it
I need a help about keeping my footer height fixed. Full of content and
I need some help about WCF and authorization. Currently I have a client which
I need some help about RegExp in AS3. I have a simple pattern :
Anyone, I need help, I got a task from my teacher, it's about jquery,
Well, I know absolutely nothing about the subject, so I really need help. I
I have one question about Yii framework, and I need your help. Basicly, I
Possible Duplicate: Detecting closest or parent div I need some help about finding elements
Since I am new to Java, I need some help about some basic things

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.