[Resolved] Refresh parent page after adding child post in new window
This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I am creating child posts for the current post using a link that opens in a new window with the child post editing form.
After the new child is created, it shows a message saying close this window to return to your application.
If possible, I would like to have the child post window close automatically when the content is saved, and then the parent window automatically refreshed to show the new child info that was created.
When you open a new window from another, the new window can refer to the source window using Window.opener (hidden link).
You would use it like this:
window.opener.location.reload();
So you will want to add a snippet of JavaScript to your child post form that on submission after a short delay (to allow time for the child post to be submitted/processed: hidden link) uses window.opener to refresh the parent, and then window.close to close the current child post window (hidden link).
You should have everything you need in those linked docs to write the JS snippet, but let me know if you need help.
add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data)
{
if ($form_data['id']==79 || $form_data['id']==130 || $form_data['id']==147)
{
function closeAndRefresh(){
opener.location.reload();
window.close();
}
}
}
I've added it to my functions.php so it should cover all of my child forms and their popup windows, but i am missing something so it doesn't work. Javascript is my weakest area, my apologies.
One more thing, the script causes an alert to popup saying "Operation completed successfully" which has to be closed before the window will close and the parent will refresh.
I have seen several threads about this that say the issue will be resolved in a future release.
is it possible to suppress this popup in the latest beta?
I have found a workaround for the "Operation Completed Successfully" dialog!
All you have to do is to set the form the "Display a message instead of the form..." and the window automatically closes and the parent refreshes without the extra dialog to click!