1

I have an unbound form with two fields that i would like to validate. I would like to use the built in NotBlank on both fields and my two custom validators MyFile and *UploadConstraints *. The problem is i can get all three to work together. The UploadConstraints is called before the NotBlanks() and if i comment the UploadConstraints the attachment constraints does not fire, i used UploadConstraints to refer to both fields.

$builder
            ->add('country', 'entity',array(
                'class' => 'WarrDigicelBundle:Country',
                'property' => 'name',// display of countries
                'label' => 'Country:',
                'empty_value' => '',
                'empty_data'  => null,
                'required' => false,
                'constraints' => new NotBlank(),

            ))

            ->add('attachment', 'file',array(
                'label' => 'Upload:',
                'required' => false,
                'constraints' => new NotBlank(),
                'constraints' => array( new Constraints\MyFile())

            ))
            ->add('Upload File', 'submit')
        ;
    }

   public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => null,
            'cascade_validation' => true,
            'constraints' => array( new Constraints\UploadConstraints())

        ));
    }
2
  • Why did you set twice the constraints option ? Commented Jul 28, 2014 at 21:54
  • thanks fro your reply, because whenever i tried also 'constraints' => array(new NotBlank(), new Constraints\MyFile()) this doesn't work period. Plus i would like the UploadConstraints to run after the other two constraints Commented Jul 28, 2014 at 22:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.