terminal42 / contao-mp_forms

Real step separation in the form generator of the Contao Open Source CMS
25 stars 13 forks source link

Error file upload widget and mandatory attribute #33

Closed zonky2 closed 5 years ago

zonky2 commented 5 years ago

it is not possible to move to the next step if you have an upload field as mandatory and this is not the last step - the file is loaded on the server, but there is always an error message that the file is missing...

e.g. is this a solution: set hack before validate the widget - works at me... https://github.com/terminal42/contao-mp_forms/blob/master/MPFormsFormManager.php#L434

    public function validateField(FormFieldModel $formField, $step)
    {
// ....
+        // Special hack for upload fields because they delete $_FILES and thus
+        // multiple validation calls will fail - sigh
+        if ($widget instanceof \uploadable && isset($_SESSION['FILES'][$widget->name])) {
+            $_FILES[$widget->name] = $_SESSION['FILES'][$widget->name];
+        }

        $widget->validate();

        // HOOK: validate form field callback
        if (isset($GLOBALS['TL_HOOKS']['validateFormField']) && is_array($GLOBALS['TL_HOOKS']['validateFormField'])) {
            foreach ($GLOBALS['TL_HOOKS']['validateFormField'] as $callback) {

                $objCallback = System::importStatic($callback[0]);
                $widget = $objCallback->{$callback[1]}($widget, $this->getFormId(), $this->formModel->row(), $form);
            }
        }

        // Reset fake validation
        if ($fakeValidation) {
            Input::setPost($formField->name, null);
        }

-        // Special hack for upload fields because they delete $_FILES and thus
-        // multiple validation calls will fail - sigh
-        if ($widget instanceof \uploadable && isset($_SESSION['FILES'][$widget->name])) {
-            $_FILES[$widget->name] = $_SESSION['FILES'][$widget->name];
-        }

        return !$widget->hasErrors();
    }
Toflar commented 5 years ago

You're change only worked by chance. It would not fix the real issue. It would actually cause validation to fail on other pages then 😄 Fixed in eb25a726bf98ef9215aa011e9feb3fa55095e454. Can you check if this works for you?

zonky2 commented 5 years ago

Error :(

Symfony\Component\Debug\Exception\FatalThrowableError:
Type error: Too few arguments to function MPFormsFormManager::storeData(), 2 passed in /kunden/532252_10969/webseiten/contao4_healthy-hub.de/vendor/terminal42/contao-mp_forms/MPForms.php on line 121 and exactly 3 expected

  at vendor/terminal42/contao-mp_forms/MPFormsFormManager.php:267
  at MPFormsFormManager->storeData(array(), array())
     (vendor/terminal42/contao-mp_forms/MPForms.php:121)
  at MPForms->prepareFormData(array(), array(), array(object(FormFieldModel), object(FormFieldModel), object(FormFieldModel), object(FormFieldModel)), object(Form))
     (vendor/contao/core-bundle/src/Resources/contao/forms/Form.php:316)
  at Contao\Form->processFormData(array(), array(), array(object(FormFieldModel), object(FormFieldModel), object(FormFieldModel), object(FormFieldModel)))
     (vendor/contao/core-bundle/src/Resources/contao/forms/Form.php:259)
  at Contao\Form->compile()
     (vendor/contao/core-bundle/src/Resources/contao/classes/Hybrid.php:236)
  at Contao\Hybrid->generate()
     (vendor/contao/core-bundle/src/Resources/contao/forms/Form.php:89)
  at Contao\Form->generate()
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:480)
  at Contao\Controller::getContentElement(object(ContentModel), 'main')
     (vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php:183)
  at Contao\ModuleArticle->compile()
     (vendor/contao/core-bundle/src/Resources/contao/modules/Module.php:220)
  at Contao\Module->generate()
     (vendor/contao/core-bundle/src/Resources/contao/modules/ModuleArticle.php:65)
  at Contao\ModuleArticle->generate(false)
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:420)
  at Contao\Controller::getArticle(object(ArticleModel), false, false, 'main')
     (vendor/contao/core-bundle/src/Resources/contao/library/Contao/Controller.php:279)
  at Contao\Controller::getFrontendModule('0', 'main')
     (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:174)
  at Contao\PageRegular->prepare(object(PageModel))
     (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:47)
  at Contao\PageRegular->getResponse(object(PageModel), true)
     (vendor/contao/core-bundle/src/Resources/contao/controllers/FrontendIndex.php:306)
  at Contao\FrontendIndex->renderPage(object(Collection))
     (vendor/contao/core-bundle/src/Resources/contao/controllers/FrontendIndex.php:75)
  at Contao\FrontendIndex->run()
     (vendor/contao/core-bundle/src/Controller/FrontendController.php:42)
  at Contao\CoreBundle\Controller\FrontendController->indexAction()
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:200)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (web/app_dev.php:69)
Toflar commented 5 years ago

Please, update to the hotfix branch. You have to test the latest version not just these changes.

zonky2 commented 5 years ago

o.k. - 3.0.9 works fine!

THX