Skip Navigation

[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.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Author
Posts
#630747

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.

How can I do this?

#630748

You can see what I mean here:

hidden link

If you click either the add Co-Applicant or the Add Emergency contact links, the appropriate form opens.

#630850

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi James

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.

#631027

Here's what I have come up with:

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.

#631073

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi James

You can't mix PHP (server) and JavaScript (browser) like that.

I didn't get time to test it, but I expected something like this:

( function( $ ) {
	$( document ).ready( function(){
		
		$('.wpt-form-submit').click( function(){

			window.setTimeOut( function(){

				window.opener.location.reload();
				window.close();

			}, 2000 );

		});

	});
})( jQuery );

You should add that to the custom JS block of your child CRED form.

Your form would need to submit via Ajax and to not redirect, i.e. to keep displaying the form.

#631094

OK, that worked with one small correction:

you had setTimeOut and it should be setTimeout.

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?

#631098

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

No. It's in the pipeline to be fixed when the betas go to final release, but in the meantime there is no fix or workaround, I'm afraid.

#631110

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!

#631375

Great, thanks for sharing this.

Can I assist you with any further detail related to the topic?

#631463

All good on this one, thanks!