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] TransformationFailedException with JSON submitted data #31017

Closed
asentner opened this issue Apr 8, 2019 · 6 comments
Closed

[Form] TransformationFailedException with JSON submitted data #31017

asentner opened this issue Apr 8, 2019 · 6 comments

Comments

@asentner
Copy link

asentner commented Apr 8, 2019

Symfony version(s) affected: 3.4.24 / 4.2.5

Description
TransformationFailedException thrown when JSON is submitted through HiddenType field. I have one form that is passing a JSON which is a canvas map of a captured signature.

This commit creates the breaking change for us:

symfony/form@4f7d286#diff-9c65c1fe9e9fce8398f48544b0bbf2a5

Specifically this block of code:

} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) {
    $submittedData = null;
    $this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.');
}

This runs before a transformer can clean the data and a mapper does not seem to be a good fit for this.

How to reproduce
Submit JSON through a HiddenType form field

Possible Solution
Check for an additional form option scalar = false or something along those lines.

Example JSON:

[  
   {  
      "lx":132,
      "ly":67,
      "mx":132,
      "my":66
   },
   {  
      "lx":118,
      "ly":27,
      "mx":118,
      "my":26
   },
   {  
      "lx":144,
      "ly":19,
      "mx":144,
      "my":18
   }
]

This can get quite large depending on the size of the complexity of the signature. Transformers and mappers seem to run after this exception is thrown.

Thoughts?

@HeahDude
Copy link
Contributor

HeahDude commented Apr 8, 2019

Hello @asentner, thank you for opening this issue.

I don’t really understand the necessary steps to reproduce. It seems to me that submitting some json means submitting a string that should not break a hidden field submission. How do you handle transformation exactly?

@dmaicher
Copy link
Contributor

dmaicher commented Apr 8, 2019

This seems to be the same issue as reported in

#29809
#29841

?

@HeahDude
Copy link
Contributor

HeahDude commented Apr 8, 2019

Yes we should close here.

@fabpot
Copy link
Member

fabpot commented Apr 9, 2019

Closing as a duplicate then.

@Pasuvan
Copy link

Pasuvan commented Oct 15, 2019

Hi @ALL, @asentner
Did you solve the above issue, Can you explain how to you solved? Because I have the same issue.
Please help me.

@lushc
Copy link

lushc commented Dec 10, 2019

The solution to this issue can be found here: #29809 (comment)

Specifically, you need to create & use a new form type that allows you to submit this kind of unstructured data: https://github.com/sulu/SuluArticleBundle/blob/c0ed0b34b2903d517f555811276d0ad7f598497e/Document/Form/UnstructuredType.php#L12-L32

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

8 participants