Jump to content
James F Carr

How to Pass Data to Modal Edit Windows

Recommended Posts

In the admin, I am trying to access data from a page that contains an inputfieldand autofill that data into the modal edit window for a new entry.

For instance, I have a template which contains a PageTable field. When I add a new entry to the PageTable, I want to capture the ID from the originating admin page and add it to a field in the edit modal as a way of linking the new entry back to the originating page. The new PageTable entries are NOT children of the originating page, and cannot be for structural reasons. I have attached an image which I hope will help to clarify the basic result I want to achieve.

Is there a practical means of accomplishing this? I've been able to achieve something similar with the ConnectPageFields module, but it does not work with PageTable fields. Any input would be much appreciated.


Share this post

Link to post
Share on other sites

it has been discussed a lot on some topics, and it was determined that there is currently no easy way to pass data to the modal/page.

One way to achieve it is to hook into the save of the owning page and at that point cycle through the items in the page table, setting that field to the owning page. This works fine, however is risky in case the users do not save the owning page after adding new items to the page table. You could optionally also run a cron job to scan though the pages and look for items missing that field and set them that way.

Another way I have achieved this by using a custom 'page table' which i create using @kongondo's Runtime Markup, then i can put anything i want in the add new button (url params); Then i capture the input into a session variable, use that to set the field, then clear the session variable, hooking into save of the new item.

To do it in a Page Table without doing the first way i suggested here and in the linked topic, i think you'd likely need to add a url parameter to the popup which means hooking into the button markup. This is the structure of the add new button:

<a class="InputfieldPageTableEdit" data-url="/manage/page/edit/?id=9999&modal=1&context=PageTable" href="#">Title of Page</a>

if you could add a url param, like &ownerPage=1234 you could then capture the input and use it to set the field. You'd need to have a hook on the save of the new page;

I may be working on this so if i come up with a definitive solution will post back; i do think this is something that should have a decent recipe solution since it seems to come up often in my IA requirements.

  • Like 2

Share this post

Link to post
Share on other sites

@Macrura, thanks for the quick and thorough response. I'd been searching the forums for quite a while, yet had apparently failed to find the proper search phrasing.

I can always provide an option to select the originating page with a dropdown or autocomplete, it's just not efficient from a UX perspective and provides additional opportunity for input errors. It might just be something I have to work around during the development process until I can find a more elegant solution.

Share this post

Link to post
Share on other sites

i do have a client with a pretty big site where i do the cycle through the pages and set the owning page on those page table items;

but now i have to add a cron job to set them because the client keeps forgetting to save the owning page

and then even though those page table items are connected to the owning page by their existence in the page table field, they are still 'orphans' in the sense that the front end code we use needs to be able to identify any of those page table items' owning page without having to do a lookup;

part of the reason is that this site was built before Page Table was invented;

otherwise i think this method is the most reliable and easiest, here is some example code:

if($page->template == 'class') {
	$sessionsUnset = $page->session_table->find("class=");
	foreach($sessionsUnset as $su) {
		$su->class = $page;
		$this->message("This class ({$page->title}) added to session {$su->id}");    


  • Like 1

Share this post

Link to post
Share on other sites

Despite Soma helpfully telling us we are all wrong, the code I suggested in that thread works for me:

So you set up a field in each PageTable template to hold some reference to the container page - in the example below I use an integer field for the page ID, but you could use a Page Reference field instead. You would set the field to hidden so users do not see or change it. But for demonstration purposes I have left the field visible and also show the value in the PageTable columns.

Note that the value is only set when the PageTable field does the AJAX reload (when the modal closes), so the value is not available when adding a new page to the PageTable until the modal is closed.

In /site/init.php

$wire->addHookBefore('InputfieldPageTableAjax::checkAjax', function($event) {
    $field_name = $this->input->get('InputfieldPageTableField');
    // Just for this PageTable field
    if($field_name !== 'test_pagetable') return;
    $page_id = (int) $this->input->get('id');
    $item_id = (int) $this->input->get('InputfieldPageTableAdd');
    if($page_id) $page = $this->pages->get($page_id); // $page is the container page
    if($item_id) $item = $this->pages->get($item_id); // $item is the PageTable item
    // Set integer field to $page->id
    $item->setAndSave('container_page_id', $page->id);


  • Like 6

Share this post

Link to post
Share on other sites

@Robin S. Excellent solution! I think it is worth mentioning in the other thread that the solution does work (and cross-reference it with this GIF)...to help those who come across that thread. Ta.

  • Like 3

Share this post

Link to post
Share on other sites

this is amazing, wish i saw this about 2 hrs ago (before i wasted a bunch of time trying it another way...)

  • Like 1

Share this post

Link to post
Share on other sites

I'm not sure what was the point exactly. It works, but I need the id the moment I created the page table page not after saving it.

  • Like 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.

  • Similar Content

    • By codevark
      The Minimal Site works fine, but if I try to login as admin, I have no idea what the credentials are.
      I did not do the "install" process myself. The OVA came with everything set up, but there's no mention of the PW admin credentials being set to some initial value.
      Wondering if anyone else has tried the Bitnami OVA and if there's a simple answer.
    • By vwatson
      I don't have any fontawesome icons in the admin section. Not sure what's wrong. They used to appear. I've tried all the user profiles and they're gone in all of them.
      Using the browser inspector tool, I see this message:
      Access to font at 'https://www.domain.com/wire/templates-admin/styles/font-awesome/fonts/fontawesome-webfont.ttf?v=4.7.0' from origin 'http://domain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
      I'm not sure why this is occurring or how to fix it. Any help would be greatly appreciated. 
    • By quickjeff
      Hi Guys, 
      I have been debugging a site for the last 2 hours and cannot solve the issue. 
      I have a site running on 3.0.148. 
      I installed the Kongondo Blog module and was updating the templates to include the website style. 
      Once everything was set and done, I checked the page tree to see an error appear. 
      Template must be assigned a name before 'filename' can be accessed
      The same error appears in templates. 
      Debugging Steps
      I checked the templates in the server to ensure I didnt accidentally delete the namespace.  Deleted cache in browser and server under assets Still no go. 
      Any help is appreciated. 
    • By Andi
      Getting a little deeper into the ProcessWire state-of-mind here. I seriously think I wouldn't have come back to webdev if it wasn't for this wonderful little gem of a CMS.
      I have an "Options" field added to all users on a site. If the user has anything other then "default" selected, I would like to show a permanent message in the admin like the one in the screenshot, only so that the user can't close it. As a friendly reminder that he changed that option from default to something crazy 🙂
      I've read up on how to send messages to users, but where would I hook into to make this show up all the time in the backend?
      Thanks in advance!

    • By Spyros
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
  • Create New...