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

fileTree - bad request #51

Closed
Misco opened this issue Jun 18, 2019 · 18 comments
Closed

fileTree - bad request #51

Misco opened this issue Jun 18, 2019 · 18 comments
Assignees
Labels
bug Something isn't working ready for testing Ready for testing. Wait for response.
Milestone

Comments

@Misco
Copy link

Misco commented Jun 18, 2019

Hello,

i get an error when selecting a file with mcw:
mootools.min.js,mooRainbow.min.js,chosen.min.js,simplemodal.min....-335f0911.js:1 POST http://hiddenurl.de/contao?do=Produkte&act=edit&id=43&rt=RCRDuSTG1gpVyN0e450RkTyzIWGORbyEZzl27b9d4Ns&ref=78qZ1WDQ 400 (Bad Request)

i use this dca:

$GLOBALS['TL_DCA'][$strName]['fields']['auszeichnungen'] = array
(
	'label'			=> &$GLOBALS['TL_LANG'][$strName]['auszeichnungen'],
	'exclude' 		=> true,
	'inputType' 	=> 'multiColumnWizard',
	'eval' 			=> array
	(
		'columnFields' => array
		(			'a_media' => array
			(
                'label'                 => &$GLOBALS['TL_LANG'][$strName]['a_media'],
	            'inputType'             => 'fileTree',
                'eval'                  => array('fieldType'=>'radio', 'files'=>true, 'filesOnly'=>true, 'multiple'=>false)
            )
		)
	),
	'sql'                     => "blob NULL"
);

Contao 4.7 with own extension in src, mcw dev-master

@martin-netprofit
Copy link

Hello,
i get the same error :(

@discordier
Copy link
Member

Need more information, what is the reason for the 400? What do the logs tell?

There is nothing we can "guess" here aside from rebuilding your setup for which we simply do not have the time at the moment.

If you shed more (detailed) light on the basics like: "If I do X, I expect Y but instead Z happens."
Above we have X and Y but the Z lacks fundamental information (HTTP 400 might be ANYTHING).

@marksturm
Copy link

same issue... lates Contao and mcw-version, nothing else installed.

"If I use the fileTree in mcw, I expect to pick up an image from the filetree with the same behavoir as in the normal use-case as in a normal dca, but instead of it i get a HTTP 400 Error."

On first use/try:
Failed to load https://myserver.tdl/contao?do=news&table=tl_news&id=4&act=edit&ref=pdl3oCoJ&rt=Qo_vTJkhtk2LyIDD5uZBLz9TRPstUzwhKKQh18RONi8 resource: the server responded with a status of 400 (Bad Request)

On second use/try:
mootools.min.js,mooRainbow.min.js,chosen.min.js,simplemodal.min....-81fb3e27.js:1 POST https://myserver.tdl/contao?do=news&table=tl_news&id=4&act=edit&rt=KY8fixOjpiz_18SeI7hSb9KoRn0PxkGJ_DgY5vU1iM4&ref=pdl3oCoJ 400 (Bad Request)

the problem as Video:
mcw.mov.zip

The Video shows also a other error on second 8th...

@zonky2 zonky2 added the bug Something isn't working label Jul 13, 2019
@zonky2 zonky2 added this to the 3.4.2 milestone Jul 13, 2019
@discordier discordier modified the milestones: 3.4.2, 3.4.3 Jul 23, 2019
@henobi
Copy link

henobi commented Aug 15, 2019

I'm getting the same error.

[2019-08-15 20:26:15] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\BadRequestHttpException: "Bad request" at /Users/hendrik/Repository/project/vendor/contao/core-bundle/src/Resources/contao/classes/Ajax.php line 282 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException(code: 0): Bad request at /Users/hendrik/Repository/project/vendor/contao/core-bundle/src/Resources/contao/classes/Ajax.php:282)"} []

Code:

// vendor/contao/core-bundle/src/Resources/contao/classes/Ajax.php line 282 ff.

 // The field does not exist
if (!isset($GLOBALS['TL_DCA'][$dc->table]['fields'][$strField]))
{
   $this->log('Field "' . $strField . '" does not exist in DCA "' . $dc->table . '"', __METHOD__, TL_ERROR);
   throw new BadRequestHttpException('Bad request');
}

Seems like contao is expecting a simple field name and can not handle the MCW representation.

$strField in my case was gallery2[0][picture].

@patrickjDE
Copy link

patrickjDE commented Sep 4, 2019

Seems like contao is expecting a simple field name and can not handle the MCW representation.

$strField in my case was gallery2[0][picture].

There's logic to handle the reloadFiletree/reloadPagetree ajax calls, but the hook/event listener that changes the action parameter of the ajax request, so it'll be handled by mcw instead of the contao core is not executed in this case.

As the field name does not match the requested pattern, it returns at this point:
https://github.com/menatwork/contao-multicolumnwizard-bundle/blob/d4a0b333ed5bfe7c0f4450449a60ac969040e980/src/EventListener/Contao/InitializeSystem.php#L48-L50

For some reason the field names seem to be missing the "row_" part.

Edit: Maybe the name shouldn't contain "row_"? I don't know the internal workings of mcw well enough to tell, but it kinda looks like it to me. In that case, the changes from 2ca3e5a might be the root cause.

@Aziz-JH
Copy link
Contributor

Aziz-JH commented Oct 8, 2019

I got a similar error since Contao 4.7.7 and contao-multicolumnwizard-bundle 3.4.2.
There are changed in FileTree.php and PageTree.php the Backend.openModalSelector post name.
See: contao/contao@279f94c and contao/contao#499

I don't see any way to fix this currently and cant update the project.

Before update:

$("ft_imageHeroSlider[0][image]").addEvent("click", function(e) {
    e.preventDefault();
    Backend.openModalSelector({
        "id": "tl_listing",
        "title": "image",
        "url": this.href + document.getElementById("ctrl_imageHeroSlider_row0_image").value,
        "callback": function(table, value) {
            new Request.Contao({
                evalScripts: false,
                onSuccess: function(txt, json) {
                    $("ctrl_imageHeroSlider_row0_image").getParent("div").set("html", json.content);
                    json.javascript && Browser.exec(json.javascript);
                }
            }).post({"action":"reloadFiletree", "name":"imageHeroSlider_row0_image", "value":value.join("\t"), "REQUEST_TOKEN":"token"});
        }
    });
});

After update:

$("ft_imageHeroSlider[0][image]").addEvent("click", function(e) {
    e.preventDefault();
    Backend.openModalSelector({
        "id": "tl_listing",
        "title": "image",
        "url": this.href + document.getElementById("ctrl_imageHeroSlider_row0_image").value,
        "callback": function(table, value) {
            new Request.Contao({
                evalScripts: false,
                onSuccess: function(txt, json) {
                    $("ctrl_imageHeroSlider_row0_image").getParent("div").set("html", json.content);
                    json.javascript && Browser.exec(json.javascript);
                }
            }).post({"action":"reloadFiletree", "name":"imageHeroSlider[0][image]", "value":value.join("\t"), "REQUEST_TOKEN":"token"});
        }
    });
});

@Stefanmelz
Copy link

Stefanmelz commented Nov 11, 2019

any new information? The Fork from Aziz isnt working for me in Contao 4.4.44

@stefanheimes stefanheimes modified the milestones: 3.4.3, 3.4.4 Dec 1, 2019
@leonexcc
Copy link

leonexcc commented Jan 8, 2020

My dirty fix was this:

diff --git a/src/EventListener/Contao/ExecutePostActions.php b/src/EventListener/Contao/ExecutePostActions.php
index 65ec51b4e2f35e9fc4ccc0fb2209851b3a08f728..356f811048ee3551dcaf7970cb44c3218e8d7a06 100644
--- a/src/EventListener/Contao/ExecutePostActions.php
+++ b/src/EventListener/Contao/ExecutePostActions.php
@@ -158,9 +158,18 @@ class ExecutePostActions extends BaseListener
         $strField = $container->inputName = \Input::post('name');
 
         // Get the field name parts.
-        $fieldParts = preg_split('/_row[0-9]*_/i', $strField);
-        preg_match('/_row[0-9]*_/i', $strField, $arrRow);
-        $intRow = substr(substr($arrRow[0], 4), 0, -1);
+        if (preg_match('/^([0-9a-zA-Z]+)\[([0-9]+)\]\[([0-9a-zA-Z]+)\]/i', $strField, $arrMatches)) {
+            $fieldParts = [$arrMatches[1], $arrMatches[3]];
+            $intRow = intval($arrMatches[2]);
+        } else {
+            System::log(
+                'Invalid field name "'.$strField.'"',
+                __METHOD__,
+                TL_ERROR
+            );
+            throw new BadRequestHttpException('Bad request');
+        }
+
 
         // Rebuild field name.
         $mcwFieldName    = $fieldParts[0] . '[' . $intRow . '][' . $fieldParts[1] . ']';
diff --git a/src/EventListener/Contao/InitializeSystem.php b/src/EventListener/Contao/InitializeSystem.php
index f3c4fc004e16436607aea2574889dd099092cd3e..3ad1de23c157e6cd5bfde475fe904f72ea8db038 100644
--- a/src/EventListener/Contao/InitializeSystem.php
+++ b/src/EventListener/Contao/InitializeSystem.php
@@ -45,7 +45,7 @@ class InitializeSystem
         }
 
         $name = \Input::post('name');
-        if (!\preg_match('/_row[0-9]*_/i', $name)) {
+        if (!\preg_match('/^[0-9a-zA-Z]+\[[0-9]+\]\[[0-9a-zA-Z]+\]/i', $name)) {
             return;
         }

Maybe this helps someone.

stefanheimes added a commit that referenced this issue Mar 8, 2020
- Fix post ajax contao name changes. See #51.
stefanheimes added a commit that referenced this issue Mar 8, 2020
Hoftix release 3.4.4

- Fix post ajax contao name changes. See #51.
- Replace the class invisible with hidden
- Hotfix css full with for the wizard.
- Add the documentation for the hidden buttons.
@stefanheimes stefanheimes modified the milestones: 3.4.4, 3.4.5 Mar 8, 2020
@zonky2 zonky2 added the ready for testing Ready for testing. Wait for response. label Mar 11, 2020
@zonky2 zonky2 modified the milestones: 3.4.5, 3.4.4 Mar 11, 2020
@zonky2
Copy link
Contributor

zonky2 commented Mar 31, 2020

no response - I close the issue

@zonky2 zonky2 closed this as completed Mar 31, 2020
@Total-Reality
Copy link

fileTree still doesn't work in 3.4.9 :(

@zonky2
Copy link
Contributor

zonky2 commented Jan 12, 2021

Contao 3.5 and lower is no longer in service

@Total-Reality
Copy link

Total-Reality commented Jan 15, 2021

Contao 4.9
MCW 3.4.9

Btw. "Contao 3.4.9" does not exist https://de.wikipedia.org/wiki/Contao

Update: I think the columnsCallback could be the reason... it is buggy or not all features are included. Look also here please menatwork/MultiColumnWizard#118

@zonky2
Copy link
Contributor

zonky2 commented Jan 15, 2021

Contao 4.9
MCW 3.4.9

/* Fields */
$GLOBALS['TL_DCA'][$strTblName]['fields']['mcwtest'] =
    [
        'exclude'   => true,
        'inputType' => 'multiColumnWizard',
        'eval'      => [
            'minCount'     => 2,
            'maxCount'     => 4,
            'columnFields' => [
                'a_media' => [
                    'label'     => 'File',
                    'exclude'   => true,
                    'inputType' => 'fileTree',
                    'eval'      => ['fieldType' => 'radio', 'files' => true, 'filesOnly' => true, 'multiple' => false]
                ],
            ],
        ],
        'sql'       => "blob NULL"
    ];

see first post

works fine

FireShot Pro Webpage Screenshot #206 - 'Articles › MCW-Test › Content elements › Edit content element ID 26 I mm220_dev_metamodel_me' - mm

... for all other open a new issue

@Total-Reality
Copy link

This does not work with columnsCallback...

@zonky2
Copy link
Contributor

zonky2 commented Jan 15, 2021

solange Du Deine Code nicht postest, teste ich NIX!

@Total-Reality
Copy link

Total-Reality commented Jan 15, 2021


$GLOBALS['TL_DCA'][$strTblName]['fields']['mcwtest'] =
[
    'exclude'   => true,
    'inputType' => 'multiColumnWizard',
    'eval'      => [
        'minCount'     => 2,
        'maxCount'     => 4,
        'columnsCallback' => array('tl_mcw_test', 'getExtraFields'),
    ],
    'sql'       => "blob NULL"
];


class tl_mcw_test extends Backend
{
  public function getExtraFields()
  {

    $arrFields = array
    (
      'min' => array
      (
        'label'              => 'Min',
        'inputType'          => 'text',
        'eval'               => array('rgxp'=>'digit', 'maxlength'=>5, 'style'=>'width:50px')
      ),
      'a_media' => array
      (
        'label'              => 'File',
        'inputType'          => 'fileTree',
        'eval'               => array('fieldType' => 'radio', 'files' => true, 'filesOnly' => true, 'multiple' => false, 'style'=>'width:150px')
      )
    );

    return $arrFields;
  }
}

@zonky2
Copy link
Contributor

zonky2 commented Jan 15, 2021

das hat doch mit dem Code aus https://github.com/menatwork/contao-multicolumnwizard-bundle/issues/51#issue-457456709 nichts zu tun - wie geschrieben: mach bitte ein neues Ticket auf

@Total-Reality
Copy link

Stimmt. Sorry, mein Fehler...
Er verwendet ja auch columnFields... Ich hatte nur den Titel gelesen "bad request"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready for testing Ready for testing. Wait for response.
Projects
None yet
Development

No branches or pull requests