posting variables between windows in php - php

my title may not be clear. But basically what I want to do is:
There will be a link in my php form
<a href="somepage.php" target=_blank>Update</a>
when the user clicks on the link, a new browser window opens and allows him to select some options. There will be close button in that window. When he clicks on that 'close' button, there is a post form from where the parent window should get the selected value.
When I get that selected value from that child browser window, how I am going to refresh parent browser window to reflect what user has selected in child window?
Environment : PHP
Can anyone give me some idea?

As far as I know you can't refresh a parent window using PHP (or, more correctly, pure HTML). You will need a bit of Javascript in your onLoad event:
window.opener.location.reload(); // Refresh
- or -
window.opener.location.href = "targetpage.php"; // Redirect
You would be able to refresh a child window that was opened before from that page using a named target:
<a href="new_window.php" target="my_new_window_i'm_going_to_refresh">
(apostrphe for demonstration purposes only :)
repeated clicking on that link should refresh the child every time. It doesn't work the other way round, though.

In parent expect the refreshed values something like as:
parent.php?value=xxx
on popup, when user clicks close, you can always use window.opener.location = "parent.php?value=XXX" ... this will refresh the parent with the value selected.

Related

Pass value from pop up to parent window via window.opener

I know that similar questions have been asked before but I have not been able to find one that uses window.opener in the same way that I have.
I have a page that opens a pop up to display/edit/delete values in a db. Once it has done it's thing I use this to end the script and go back to the parent.
die( "<script>window.opener.location.reload();window.close();</script>");
This works well but I would like to pass a value back to the parent that I can use $_GET to retrieve.
This is for a a calendar and I use the above code to refresh the parent page so that the changes made to the diary event displayed in the pop up are automatically displayed (otherwise the user has to refresh themselves). At the moment when the page refreshes it goes back to the default date which is today rather than the date of the event affected. I would like to pass the date back to the parent
tia
Sorted it, thought of a much simpler answer, I used sessions instead, kept it simple
you can put a js code into your popup window
<script>
window.opener._newVar = "new value for parent window";
// now you can direct access (_newVar) after popup closed.
</script>
Instead of .reload(), just navigate to the same page with the querystring you want by setting location.search:
window.opener.location.search = "?value=" + val; window.close();

can a web page be manipulated through ajax from new window?

Hi... I want to know that when a user posts a comment to my site ... to open a web page (in new window, with a fixed width and height like window.open ) which contains the form and after submit, I want to close that windows and show that comment in the parent page through ajax ... (or i guess after closing that window, to auto reload the parent page ... I don't know ) ...
Is there any solution to this .. ?
Or what is the best way to open a pop-up which contains the form (not a new window) ?
Thank you very much.
Attach an onclick handler on whatever you use to let the user make a comment
This handler pops up the new window with the form
The form submits the comment to the server via ajax
Once the ajax handler is done on the server, it returns the comment's ID to the form window script
the form window script calls a function in the original window, passing in the comment ID, telling the window to load up the new comment (via another AJAX call, or directly passing the comment details from the form page)
the form page script then closes the window.
on the popup window form tag add target="_PARENT"
on the popup window change the submit button to normal button.
on the popup window, when button clicked, submit the form with js and close the window.
document.formname.submit();
this.close();
in this case your popup window is just to get data then the data will be posted to the main window...
You can access the parent window by using the window.opener JavaScript property. More info here
Does it have to be a new window? Why not a modal form? Take a look at this basic jQuery modal form.

how can I get just a single div to refresh on submit as apposed to the entire page?

Merged with how can I get just a single div to refresh on submit as apposed to the entire page?.
I am working with a dynamically generated page written in PHP. The page contain contents listed, while clicking the edit link a new page will open as popup using fancybox . Once editing is complete and the user closes the FancyBox modal the changes need to be reflected on the parent page.
Right, so I was able to find a solution that refreshes the entire page on submit using
parent.location.reload (true);
to refresh the entire parent page. But, that causes a browser prompt that is confusing to users and a bit of over kill as I really only need the information edited to refresh.
how can I get just a single div to refresh on submit as apposed to the entire page??????

Can I Pass value from form to popup window, display something based on what was passed, then pass something back?

I need to do this using PHP and Javascript.
I have one form, with a few inputs. One of them is gender.
When they click a link/button I need to pass the value of the gender drop down to a popup.
Based on that value I show either male or females portraits.
I'd like to pass the value back to the parent window once they select a portrait and then click a button.
I have the code to display the portaits. But how do I pass the values back and forth, and how do I make a value passed from the parent window available to my PHP code in the new popup?
Any help greatly appreciated.
The problem is well defined, but the question itself is still somewhat vague. I'll give it a shot though. If you really mean a pop-up (separate window) rather than an on-page dialog (such as jQuery UI elements and so forth), then the communication channel you'll want to use is the object returned from window.open() to communicate from parent page to child page, and window.opener to communicate from child to parent. For example:
var genderPicker = document.getElementById('genderSelect');
var gender = genderPicker.options[genderPicker.selectedIndex].value;
var portraitChooserWindow = window.open("path/to/script.ext?gender=" + gender);
// portraitChooserWindow is now a reference to the newly opened pop-up (or null if the browser blocked pop-ups)
From the child window, window.opener is now a reference to the parent window.

Open a popup browser window to select a record

I want to open a popup window on client PC where I will show records. The user will click on the selected row, and the popup window will disappear, but the parent Form on my page must get filled with the DB values related to the clicked row on the popup.
This is what I want to do. What is the right approach?
You should be able to send back some response to your parent window from popup window.
There is a specific javascript methods to do this. See this.
You can also use a modal popup type container which will make communication simpler and give you more control of the data. It'll also work flawlessly even if the client has any sort of popup blocker (which most do by default).
It's easy to build from scratch and there are also many jquery plugins that make it even simpler.

Categories