craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

[4.x]: FileUpload fails required validation check #12111

Closed roland-d closed 2 years ago

roland-d commented 2 years ago

What happened?

Description

We have a Formie form that has 2 FileUpload fields that are required. When we POST this form via GraphQL to Craft the submission is received and Craft starts the process to validate the data. During this validation when it gets to the FileUpload field, the data is removed from the posted submission and replaced with an empty AssetQuery. After that the field is checked if it is empty or not, this confirms it is empty because the AssetQuery is empty.

In the file /vendor/craftcms/cms/src/fields/Assets.php line 397 in class normalizeValue() the uploaded data is put in $this->_uploadedDataFiles and then returns an empty craft\element\db\AssetQuery. After that the validation starts in the file vendor/yiisoft/yii2/validators/RequiredValidator.php on line 73 and it fails the check on line 79 because it finds an empty AssetQuery and this fails the required check for the FileUpload field, so the error message is added.

The actual error is {"Resume":["Resume cannot be blank."],"CoverLetter":["Cover Letter cannot be blank."]}

I am not sure what needs to be done but I would think that the AssetQuery should be populated with at least the fileData.

Steps to reproduce

  1. Create a form in Formie
  2. Add a FileUpload field and set it to required
  3. Send a graphql mutation query, for example http://site.com/graphql?query=mutation+xxx+{save_Apply_form_Submission(CoverLetter:[{"fileData": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQUA...","filename": "testing.png"}])}
  4. Check the response saying the field cannot be empty

Expected behavior

The expected behavior is that the field is processed as expected because it is not empty

Actual behavior

The submission fails because GraphQL reports the field as being empty

Craft CMS version

Craft Pro 4.2.5.2

PHP version

8.1.0

Operating system and version

Linux 6.0.0-1-MANJARO

Database type and version

MySQL 5.5.5

Image driver and version

GD 8.1.0

Installed plugins and versions

Entry Section 1.0.0
Formie 2.0.12
Formie Description HTML 1.0.1
GraphQL Security v1.1.0
Greenhouse 1.0.0
Icon Picker 2.0.0-beta.5
Inventory 2.2.0
marketo 1.0.0
Matrix Field Preview 4.0.5
Read-only Field 2.0.1
Redactor 3.0.2
Retour 4.1.4
SEO 4.0.9
Super Table 3.0.1
Two-Factor Authentication 3.0.1
Typed link field 2.1.4
i-just commented 2 years ago

Hi, Thanks for reaching out. I believe this might be a Formie plugin issue. Can you please raise an issue here: https://github.com/verbb/formie/issues? I'll also keep investigating from our end too.

brandonkelly commented 2 years ago

Closing due to inactivity. @roland-d please do let us know if there’s more we can do to help, though.

roland-d commented 2 years ago

I have been busy with other things but this issue itself is not resolved but as requested I have posted it with Formie as well here: https://github.com/verbb/formie/issues/1130

brandonkelly commented 2 years ago

@roland-d Thanks! Following along over there.