The question was already asked (Possible to redirect elsewhere after saving an entry?) but this was about Craft 2.x
.
Up until now I used the following code in my plugin (I took it from one of the comments from the same question):
Craft::$app->getView()->hook('cp.entries.edit', function (array &$context) {
if (isset ($context['section']['type']) && $context['section']['type'] === 'single')
{
Craft::$app->getView()->registerJs("
$(function () {
$('input[name=\"redirect\"]').val('/');
});
");
}
});
The code did the job, but after I updated to 3.1.32.1
, it stopped working, every time after entry was saved the following exception was thrown:
HTTP 400 – Bad Request – yii\web\BadRequestHttpException
Request contained an invalid body param
Stacktrace:
yii\web\BadRequestHttpException: Request contained an invalid body param in .../vendor/craftcms/cms/src/web/Request.php:651
Stack trace:
#0 .../vendor/craftcms/cms/src/web/Controller.php(314): craft\web\Request->getValidatedBodyParam('redirect')
#1 .../vendor/craftcms/cms/src/controllers/EntriesController.php(595): craft\web\Controller->redirectToPostedUrl(Object(craft\elements\Entry))
#2 [internal function]: craft\controllers\EntriesController->actionSaveEntry()
#3 .../vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#4 .../vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#5 .../vendor/craftcms/cms/src/web/Controller.php(109): yii\base\Controller->runAction('save-entry', Array)
#6 .../vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-entry', Array)
#7 .../vendor/craftcms/cms/src/web/Application.php(297): yii\base\Module->runAction('entries/save-en...', Array)
#8 .../vendor/craftcms/cms/src/web/Application.php(565): craft\web\Application->runAction('entries/save-en...', Array)
#9 .../vendor/craftcms/cms/src/web/Application.php(281): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#10 .../vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#11 .../web/index.php(21): yii\base\Application->run()
#12 {main}
Is there any chance to make it work again on 3.1.32
?