jmartsch

Howto load a module or page in a modal in the backend?

Recommended Posts

I want to load a module or page in the ProcessWire Admin in a modal. Right now, I added a button on the Edit page and gave that button a class of "pw-modal". When I click this button, the modal opens with the provided URL, but then suddenly the browser redirects me to this URL. This is not how it should work. In the screencast you can see what´s happening.

Here is the code that I use to add the button to the form:

public function ready()
        {
            $this->addHookAfter('ProcessPageEdit::buildForm', $this, 'addButtons');
        }

        /**
         *    Add a button besides "Save", which lets the user accept the application
         *
         */
        public function addButtons($event)
        {
            $page = $event->object->getPage();
            if ($page->template == "bewerbung") {
                $form = $event->return;
                $accept = $this->modules->get('InputfieldButton');
                $accept->attr('id+name', 'hook_accept_application');
                $accept->attr('href', 'http://localhost/winkelmann/www/bewerbertool-talents/admin/page/edit/?id=1479');
                $accept->class .= ' ui-priority-secondary head_button_clone pw-modal';
                $accept->attr('value', $this->_('Bewerbungsunterlagen anfordern'));
                $form->append($accept, $form->get("id"));
            }
        }

 

2017-03-21_10-20-51.mp4

Share this post


Link to post
Share on other sites

The problem seems to be that the button submits the form. If I transform it into a link, the modal works fine, but the links does not look like a button.

 

Share this post


Link to post
Share on other sites

I know this old, but the answer to this question is to add:

$accept->attr('data-href',  wire('config')->urls->admin . 'page/edit/?id=1479');

Remove this line:

$accept->attr('href', 'http://localhost/winkelmann/www/bewerbertool-talents/admin/page/edit/?id=1479');

Hope that helps the next person.

  • Like 2
  • Thanks 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.