2

Trying to validate a choice field (multiple checkboxes) Im having this problem:

"Notice: Array to string conversion "

My validation file looks like this one:

Cgboard\AppBundle\Forms\UploadImageEntity:
  properties:
    image:
          ... 
    cgnetworks:
      - Choice:
          choices: [flickr, tumblr]  //<--- this is giving me problems!!!

My form entity class (Im not going to save this to db for now):

class UploadImageEntity {
    public $image;
    public $cgnetworks;
} 

And my form class:

class UploadImageForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('image', 'file')
            ->add('cgnetworks', 'choice', [
                    'choices'  => $this->getCgNetworks(),
                    'multiple' => TRUE,
                    'expanded' => TRUE
                ]
            );
    }

    public function getCgNetworks()
    {
        return [
        'tumblr' => 'Tumblr',
        'flickr' => 'Flickr'
        ];
    } 

} 

Any idea?

4

2 Answers 2

3

perhaps you need to specify multiple in your validation

cgnetworks:
  - Choice:
      choices: [flickr, tumblr]  //<--- this is giving me problems!!!
      multiple: true
Sign up to request clarification or add additional context in comments.

Comments

0

Check your Entity field getter. If you have something else instead of

public function getValue(){
      return $this->value;
}

You can reach this error.

Form builder uses get and set entity methods, that's why you need to return an allowable value.

Comments

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.