Skip to content

Form validation breaks after upgrading from 3.4.12 to 3.4.24 #30840

Closed
@cacharrin

Description

@cacharrin

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions