Hello! I have no idea is this possible with simple php/javascript and have no idea where to start!
Imagine i have page.php and there are link tag that will open open.php (opens in new tab) there on some successful form submit (and this is where it gets tricky for me) open.php need to redirect to other URL (different domain). <<< all good till this!
The question is: How to show message with result (like “all done” or any custom dynamic value) in page.php (in alert or something like that)?
I have not tried anything, have no idea how to search this in google so any tip/help is needed
I am not aware of any ways to communicate but directly using parameters (arguments), references, pointers or indirect via variables, some storage or micro services. In web development is the information stored in several layers (using different languages) which makes communication harder. So I pass this.
It’s technically doable, but not really recommended, as many browsers and plugins would block your popup (which is what it would have to be) from appearing.
That said, two distinct paths appear to my mind immediately;
a javascript controlled popup in which you monitor the window location until it became unavailable to your original script (because at that point it becomes blocked by Cross Origin Policy). This has the advantage of not requiring extra runaround, but does experience false positive results (if a user simply closes the popup instead of filling out the form, etc.)
when the link is opened, it contains a URL variable that is a uniqueID. Your javascript on page.php starts polling amidone.php asking it if uniqueID has submitted their form, waiting for it to tell you yes. Meanwhile, the form on open.php adds the uniqueID as a hidden form field. When they submit the form, a database entry gets added for uniqueID; and amidone.php can find it and answer yes to page.php and clean up the database entry (if required). At that point, page.php knows that the form was submitted, and can display whatever it needs to.
First, instead of trying to send a message (to page.php) think in terms of how page.php can get the result. I think that all the suggestions here are doing that.
Have you considered some type of single page application?
When going the AJAX route OTOH, you might open('open.php') using JS instead of a regular target="_blank" link, where again you’d submit the form using AJAX and communicate back to the opener window using postMessage(); this would be a bit more involved but you’d have a direct channel between the two pages.
One solution could be to use - php header() function to redirect the user - and store
a value in session cockie. but kinda depends what you collecting and sending ofc.