forms
forms copied to clipboard
"Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed" when submitting form with file
Hi,
I get this error when trying to submit form with a file:
"Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed"
From what I found unsetting file fields on EmailFactory level from form data passed to context ( files are preserved in attachements ) works fine
Stacktrace:
Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed
at vendor/symfony/twig-bridge/Mime/BodyRenderer.php:52
at serialize(array(array('data' => array('name' => 'Name', 'email' => '[email protected]', 'phone' => '0', 'upload' => object(UploadedFile), 'message' => 'This is a test', 'string_city_processor_string' => null), 'formname' => 'vacature', 'meta' => array('ip' => '172.18.0.13', 'timestamp' => object(Carbon), 'path' => '/vacature/online-marketing-stage', 'url' => 'http://mrwork.test/vacature/online-marketing-stage'), 'config' => object(Collection)), null, '@bolt/email/email.twig'))
(vendor/symfony/twig-bridge/Mime/BodyRenderer.php:52)
at Symfony\Bridge\Twig\Mime\BodyRenderer->render(object(TemplatedEmail))
(vendor/symfony/mailer/EventListener/MessageListener.php:125)
at Symfony\Component\Mailer\EventListener\MessageListener->renderMessage(object(TemplatedEmail))
(vendor/symfony/mailer/EventListener/MessageListener.php:72)
at Symfony\Component\Mailer\EventListener\MessageListener->onMessage(object(MessageEvent), 'Symfony\\Component\\Mailer\\Event\\MessageEvent', object(TraceableEventDispatcher))
(vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(MessageEvent), 'Symfony\\Component\\Mailer\\Event\\MessageEvent', object(TraceableEventDispatcher))
(vendor/symfony/event-dispatcher/EventDispatcher.php:230)
at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'Symfony\\Component\\Mailer\\Event\\MessageEvent', object(MessageEvent))
(vendor/symfony/event-dispatcher/EventDispatcher.php:59)
at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(MessageEvent), 'Symfony\\Component\\Mailer\\Event\\MessageEvent')
(vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151)
at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(MessageEvent))
(vendor/symfony/mailer/Transport/AbstractTransport.php:63)
at Symfony\Component\Mailer\Transport\AbstractTransport->send(object(TemplatedEmail), object(DelayedEnvelope))
(vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:132)
at Symfony\Component\Mailer\Transport\Smtp\SmtpTransport->send(object(TemplatedEmail), null)
(vendor/symfony/mailer/Transport/Transports.php:51)
at Symfony\Component\Mailer\Transport\Transports->send(object(TemplatedEmail), null)
(vendor/symfony/mailer/Mailer.php:42)
at Symfony\Component\Mailer\Mailer->send(object(TemplatedEmail))
(vendor/bolt/forms/src/EventSubscriber/Mailer.php:53)
at Bolt\BoltForms\EventSubscriber\Mailer->mail()
(vendor/bolt/forms/src/EventSubscriber/Mailer.php:45)
at Bolt\BoltForms\EventSubscriber\Mailer->handleEvent(object(PostSubmitEvent), 'boltforms.post_submit', object(TraceableEventDispatcher))
(vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(PostSubmitEvent), 'boltforms.post_submit', object(TraceableEventDispatcher))
(vendor/symfony/event-dispatcher/EventDispatcher.php:230)
at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'boltforms.post_submit', object(PostSubmitEvent))
(vendor/symfony/event-dispatcher/EventDispatcher.php:59)
at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(PostSubmitEvent), 'boltforms.post_submit')
(vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151)
at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(PostSubmitEvent), 'boltforms.post_submit')
(vendor/bolt/forms/src/Event/PostSubmitEventDispatcher.php:46)
at Bolt\BoltForms\Event\PostSubmitEventDispatcher->dispatch('vacature', object(Form), object(Request))
(vendor/bolt/forms/src/Event/PostSubmitEventDispatcher.php:35)
at Bolt\BoltForms\Event\PostSubmitEventDispatcher->handle('vacature', object(Form), object(Request))
(vendor/bolt/forms/src/FormRuntime.php:76)
at Bolt\BoltForms\FormRuntime->run('vacature')
(var/cache/dev/twig/1f/1f6b4fb345504e236615f4a234554abd08466c317846fd96203cd0458bc6a5ff.php:297)
at __TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11->block_main(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection), 'app' => object(AppVariable), 'config' => object(Config), 'seo' => object(Seo)), array('inlineStyle' => array(object(__TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3), 'block_inlineStyle'), 'bodyId' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyId'), 'bodyClass' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyClass'), 'main' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_main'), 'inlineScripts' => array(object(__TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3), 'block_inlineScripts')))
(vendor/twig/twig/src/Template.php:171)
at Twig\Template->displayBlock('main', array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection), 'app' => object(AppVariable), 'config' => object(Config), 'seo' => object(Seo)), array('inlineStyle' => array(object(__TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3), 'block_inlineStyle'), 'bodyId' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyId'), 'bodyClass' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyClass'), 'main' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_main'), 'inlineScripts' => array(object(__TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3), 'block_inlineScripts')))
(var/cache/dev/twig/9a/9a06aa87d58165d02443c1662ef6c73f29db45f0a6c30b38e95c3333e3844f29.php:263)
at __TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3->doDisplay(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection), 'app' => object(AppVariable), 'config' => object(Config), 'seo' => object(Seo)), array('inlineStyle' => array(object(__TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3), 'block_inlineStyle'), 'bodyId' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyId'), 'bodyClass' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyClass'), 'main' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_main'), 'inlineScripts' => array(object(__TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3), 'block_inlineScripts')))
(vendor/twig/twig/src/Template.php:394)
at Twig\Template->displayWithErrorHandling(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection), 'app' => object(AppVariable), 'config' => object(Config), 'seo' => object(Seo)), array('inlineStyle' => array(object(__TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3), 'block_inlineStyle'), 'bodyId' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyId'), 'bodyClass' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyClass'), 'main' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_main'), 'inlineScripts' => array(object(__TwigTemplate_cc75ee5fcab64e0f63d9ddbde3dbcdce23da5f39b15305ea70c58d655f695fd3), 'block_inlineScripts')))
(vendor/twig/twig/src/Template.php:367)
at Twig\Template->display(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection), 'app' => object(AppVariable), 'config' => object(Config), 'seo' => object(Seo)), array('bodyId' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyId'), 'bodyClass' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyClass'), 'main' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_main')))
(var/cache/dev/twig/1f/1f6b4fb345504e236615f4a234554abd08466c317846fd96203cd0458bc6a5ff.php:50)
at __TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11->doDisplay(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection), 'app' => object(AppVariable), 'config' => object(Config), 'seo' => object(Seo)), array('bodyId' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyId'), 'bodyClass' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyClass'), 'main' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_main')))
(vendor/twig/twig/src/Template.php:394)
at Twig\Template->displayWithErrorHandling(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection), 'app' => object(AppVariable), 'config' => object(Config), 'seo' => object(Seo)), array('bodyId' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyId'), 'bodyClass' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_bodyClass'), 'main' => array(object(__TwigTemplate_677ada4d956285ccc1203144f539b4a340bfcf90fb4bad463f584b3ce12e0e11), 'block_main')))
(vendor/twig/twig/src/Template.php:367)
at Twig\Template->display(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection)))
(vendor/twig/twig/src/Template.php:379)
at Twig\Template->render(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection)), array())
(vendor/twig/twig/src/TemplateWrapper.php:40)
at Twig\TemplateWrapper->render(array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection)))
(vendor/twig/twig/src/Environment.php:277)
at Twig\Environment->render(object(TemplateWrapper), array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection)))
(vendor/bolt/core/src/Controller/TwigAwareController.php:111)
at Bolt\Controller\TwigAwareController->render(object(TemplateWrapper), array('record' => object(Content), 'vacature' => object(Content), 'user' => null, 'theme' => object(DeepCollection)))
(vendor/bolt/core/src/Controller/TwigAwareController.php:161)
at Bolt\Controller\TwigAwareController->renderSingle(object(Content), true)
(vendor/bolt/core/src/Controller/Frontend/DetailController.php:55)
at Bolt\Controller\Frontend\DetailController->record('online-marketing-stage', 'vacature', true)
(vendor/symfony/http-kernel/HttpKernel.php:157)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/http-kernel/HttpKernel.php:79)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor/symfony/http-kernel/Kernel.php:195)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(public/index.php:39)
Hi,
What's the configuration of the form that causes this to happen?
honeypot: true
spam-action: mark-as-spam # Either 'block', 'none' or 'mark-as-spam'
templates:
form: '@boltforms/form.html.twig'
email: '@bolt/email/email.twig'
subject: '@boltforms/subject.html.twig'
files: '@boltforms/file_browser.twig'
layout:
form: 'form_div_layout.html.twig'
bootstrap: false # if true, bootstrap will automatically be included.
vacature:
notification:
enabled: true
debug: false
debug_address: [email protected] # Email address used when debug mode is enabled
debug_smtp: false
subject: New vacancy application
subject_prefix: ''
replyto_name: '{NAME}' # Email addresses and names can be either the
replyto_email: '{EMAIL}' # name of a field below or valid text.
to_name: '***'
to_email: "***"
from_name: '***'
from_email: '***'
feedback:
success: Message submission successful
error: There are errors in the form, please fix before trying to resubmit
fields:
name:
type: text
options:
required: true
label: Name
attr:
placeholder: Voornaam Achternaam*
constraints: [ NotBlank, { Length: { 'min': 3, 'max': 128 } } ]
email:
type: email
options:
required: true
label: Email address
attr:
placeholder: E-mailadres*
constraints: [ NotBlank, Email ]
phone:
type: phone
options:
required: true
label: Phone number
attr:
placeholder: Telefoon*
pattern: '[0-9- +()]+'
upload:
type: file
options:
required: false
label: Upload C.V.
attach: true
message:
type: textarea
options:
required: false
label: Your message
attr:
placeholder: Motivatie
class: myclass
submit:
type: submit
options:
label: Verzenden
attr:
class: button primary
This is my current configuration, no configuration changes that have I made did anything, I'm using bolt 4.1.15 with symfony 5.2.5
Is there any way this can be fixed? The problem lies in serializing the whole form context in the mail factory when files should be omitted since they can't be serialized. I could make a PR which will fix the issue.
Actually, I did fix the issue myself but since MailFactory class is not injected I can't override it.
The real fix is on the Symfony side, as far as I can see.
What fixed the error for me was only running the profiler for requests with exceptions, by setting framework.profiler.only_exceptions to true in config/packages/dev/web_profiler.yaml. Not an ideal solution, but at least it lets you get on.
There'd have to be a fix within the Symfony profiler itself for this to be fully solved, I'm afraid. Relevant issue here.