cancel and redirect page on editor.on('preSubmit'

cancel and redirect page on editor.on('preSubmit'

itramitram Posts: 43Questions: 15Answers: 0

If user tries to submit a modification and session timeout has happened, I need to cancel submit but at the same time redirect him to the login page.
So to cancel submit I understand that the event has to return false:
editor.on( 'preSubmit', function ( e, data, action ) {
if ( abortSubmit ) {
return false;
}
} );
If the above is correct, where to add the:
header("Location: loginPage.php");
to redirect to the login page in this case?

Thanks

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,021Questions: 88Answers: 421
    edited April 2022 Answer ✓

    I would simply use a timeout to make sure "false" gets returned from the event handler. I would also avoid using client side PHP ( header("Location: loginPage.php"); ).

    editor.on( 'preSubmit', function ( e, data, action ) {
        if ( abortSubmit ) {
            setTimeout(function(){
                window.location.href = "loginPage.php";
            }, 30)
            return false;
        }
    } );
    

    Please use "Markdown" to make your code legible if you want a quick answer.

Sign In or Register to comment.