Jump to content

Redirect on save from within modal window


Recommended Posts

I created a hook on ProcessPageEdit::processSaveRedirect to redirect to an external website when the edit page is saved under certain circumstances. This is working great for regular edit pages, but doesn't work for modal pages (i.e. lister). Is there a way to initiate a redirect from the modal window?

  • Like 1
Link to comment
Share on other sites

  • 5 months later...

I'm trying to figure out the same.

Got the PW3 front end edit modal and want it to redirect to changed page on save.

Reason: The edit might change the name and therefore the url of the page.

@thetuningspoon what's your code so far?

This is what I got:

$wire->addHookBefore('ProcessPageEdit::processSaveRedirect', function($event) use ($page) {
    $url = $event->arguments[0];
    
    if($this->input->get->modal && $page->process && $page->process != 'ProcessPageView') {
        $event->arguments(0, $page->url);
    }
});

It's still just closing the modal and staying on the same page..

When changing $page->url to eg "http://example.dev" I get the following error, which shows up in browser console

Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://www.happyfamily.dev" from accessing a frame with origin "null".  The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "data". Protocols must match.
Link to comment
Share on other sites

I ended up taking a different approach entirely to my problem, so this wasn't an issue. But I believe the problem is that the redirect is trying to open in the modal window (it is just an iframe), but the window is being closed by PW's javascript before (or while) the redirect is happening. I think what you would need to do is change the target attribute of the iframe's form (using javascript) to _parent when the submit button is clicked. But I haven't fully thought through the implementation yet.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...