I am using Symfony 2.6. I am trying to create a form without Entity, but get the following error:
The option "constraints" does not exist. Known options are: "action", "attr", "auto_initialize", "block_name", "by_reference", "compound", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "inherit_data", "intention", "label", "label_attr", "label_format", "mapped", "max_length", "method", "pattern", "post_max_size_message", "property_path", "read_only", "required", "translation_domain", "trim", "virtual".
My class:
<?php
/**
* @author Anderson Scouto da Silva <[email protected]>
* @copyright Copyright (c) 2015, Anderson Scouto da Silva
*/
namespace app\modules\teste\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints as Constraints;
/**
* Form Class
* @see http://symfony.com/doc/2.0/book/forms.html#creating-form-classes
*/
class MessageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('sender', 'text', [
'constraints' => [
new Constraints\NotBlank(),
],
])
->add('recipient', 'email')
->add('message', 'textarea');
}
public function getName()
{
return 'message';
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$collectionConstraint = new Constraints\Collection(array(
'fields' => [
'sender' => [
new Constraints\NotBlank(),
new Constraints\Email(),
],
'recipient' => [
new Constraints\NotBlank(),
new Constraints\Email(),
],
'message' => [
new Constraints\NotBlank(),
],
],
));
$resolver->setDefaults([
'validation_constraints' => $collectionConstraint,
]);
}
}
As can be seen, tried anyway. I also tried as is the documentation for using the component form outbox, but get the same error.
http://symfony.com/doc/current/components/form/introduction.html#form-validation
Please ask support questions on the mailing list: http://symfony.com/mailing_lists