Skip to content

[Form] Adding constraints to a non-entity related form fails #896

Closed
@jcrombez

Description

@jcrombez

Hello,

I think i found a problem in Symfony Form (2.0.6).

First : http://symfony.com/doc/2.0/book/forms.html#adding-validation

In the example, there is no return $options, it was my first problem in trying to add constraints to my form. I'm not sure of the whole correction so i didn't pull-requested anything in the symfony-doc repo yet.

Second, a more serious problem (i guess it's not really a documentation issue, but still), when FormFactory process the options, it failed to array_replace the Constraints Collection :

The code

public function getDefaultOptions(array $options)
{
    $collectionConstraint = new Collection(array(
        'time' => new Choice(array(
                'choices' => $this->times
        ))
    ));

    return $options['validation_constraint'] = $collectionConstraint;
}

The error

Warning: array_replace(): Argument #1 is not an array in /path/to/my/project/vendor/symfony/src/Symfony/Component/Form/FormFactory.php line 236 

Argument #1 being the Constraints Collection :

at array_replace (object(Collection), array('data' => ...

Am i doing something wrong or is the documentation out of date ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions