in2code-de / femanager

Modern TYPO3 Frontend User RegistrationTYPO3 Frontend User Registration and Management based on Extbase and Fluid and on TYPO3 8 and the possibility to extend it to your needs. Extension basicly works like sr_feuser_register
https://www.in2code.de/agentur/typo3-extensions/femanager/
48 stars 118 forks source link

Validation ajax action returns value with wrong header #490

Open mediaessenz opened 1 year ago

mediaessenz commented 1 year ago

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 commented 1 year ago

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