Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form validation breaks after upgrading from 3.4.12 to 3.4.24 #30840

Closed
cacharrin opened this issue Apr 2, 2019 · 2 comments
Closed

Form validation breaks after upgrading from 3.4.12 to 3.4.24 #30840

cacharrin opened this issue Apr 2, 2019 · 2 comments

Comments

@cacharrin
Copy link

cacharrin commented Apr 2, 2019

Symfony version(s) affected: 3.4.24

Description
After upgrading from Symfony 3.4.12 to 3.4.24 the form type throws validation errors.

How to reproduce
I have this entity:

class Lead{
    //more code 

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=60)
     * */
    private $loanPurpose;

    //more code
}

And the corresponding FormType (Note i'm not enforcing any data type)

class LeadType extends AbstractType{

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('loanPurpose')
            //more fields added
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => Lead::class
        ));
    }
}

Then, I have a controller where I get a json content like this:

{
   "loanPurpose":["Purpose1", "Purpose2", "Purpose3"]
}

And I process it like this:

        $data = json_decode($request->getContent(), true);

        $lead = new Lead();
        $form = $this->createForm(LeadType::class, $lead);
        $form->submit($data, true);

        if($form->isValid()) {
            //Convert array to string "Purpose1,Purpose2,Purpose3"
            $lead->setLeanPurpose(implode(",", $lead->getLeanPurpose()));
            $em->persist($lead);
            $em->flush();
       }

This code works perfectly on 3.4.12, but after upgrade to 3.4.24 it throws
leanPurpose: "This value is not valid"

What is going on?

@dmaicher
Copy link
Contributor

dmaicher commented Apr 2, 2019

This seems to be the same problem as reported in multiple other issues:

#30125
#29841
#29905
...

caused by #29307

@xabbuh
Copy link
Member

xabbuh commented Apr 4, 2019

closing as explained by @dmaicher

@xabbuh xabbuh closed this as completed Apr 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants