femanager icon indicating copy to clipboard operation
femanager copied to clipboard

Validation ajax action returns value with wrong header

Open mediaessenz opened this issue 1 year ago • 1 comments

The corresponding TypoScript set Content-Type to application/json:

feManagerValidation = PAGE
feManagerValidation {
  typeNum = 1548935210
  config {
    additionalHeaders.10.header = Content-Type: application/json
    no_cache = 0
    disableAllHeaderCode = 1
    disablePrefixComment = 1
    xhtml_cleaning = 0
    admPanel = 0
    debug = 0
  }

  10 = USER_INT
  10 {
    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
    extensionName = Femanager
    pluginName = Pi1
    vendorName = In2code
    controller = User
    action = validate
    switchableControllerActions.User.1 = validate
    features.requireCHashArgumentForActionArguments = 0
  }
}

The Action due to the usage of return $this->htmlResponse(); returns Content-Typ: text/html; charset=utf-8.

In the end, the browser doesn't get back the right format and a response for an invalid field looks like this:

{"validate":0,"message":"\n\n\t\n\t\tDies ist ein Pflichtfeld\n\t\n\t<br \>\n"}

Therefore not validation appears in the frontent and the console shows this error message:

Error: The called url is not available - if you use TYPO3 in a subfolder, please use config.baseURL in TypoScript

mediaessenz avatar Apr 06 '23 14:04 mediaessenz

Possible solution:

Change the return to:

return $this->jsonResponse();

and remove additionalHeaders.10.header from the TypoScript.

Additional remove all whitespaces from EXT:femanager/Resources/Private/Partials/Misc/ValidationMessages.html

mediaessenz avatar Apr 06 '23 15:04 mediaessenz