Jerry Stuckle wrote:
> All,
>
> I have something a little different here 0 but I'm sure you guys can
> help me out.
>
> I need to open a popup window - and get the response. The window will
> be something like:
>
> "Warning - This will delete all items in your database."
> "Are you sure you want to do this?"
>
> With Yes and No pushbuttons.
>
> Then I need to get the results back in the window which called the popup
> (using PHP).
>
> Basically - this is an "Admin" screen - so it's not available to the
> general public (protected directory).
>
> I know I could do it by opening one window in the browser with the
> information, then have it go to another window. However, I'd much
> rather do it with a popup, similar to one to enter your password when
> accessing a protected directory.
>
> Does anyone have any snippets to show how to do this?
OK, going with the popup for a minute, you should be able to use the
form's target attribute (transitional DTD only) to point the popup back
to the parent page.
The only problem with just having:
<form action="delete.php" method="post" target="_parent">
<input type="submit" value="Yes"><br>
<input type="submit" value="No">
</form>
Is that you would lose any other variables in delete.php. You can get
around this by either making those variables session variables, so that
they remain available, or if the popup is loaded from a form:
<!-- form in initial page to open popup -->
<form action="confirm.php" method="post" target="popupname">
<input type="hidden" name="blah" value="blah">
etc
<input type="submit" value="Delete">
</form>
And then:
<!-- form in popup -->
<form action="delete.php" method="post" target="_parent">
<?php
foreach ($_POST as $key => $var) {
echo "<input type=\"hidden\" name=\"" . $key . "\" value=\"" . $var
.. "\">";
}
?>
<input type="radio" name="confirmation" value="Yes"><br>
<input type="radio" name="confirmation" value="No" checked="checked">
<input type="submit" name="go" value="Proceed">
</form>
The similar thing can be done with a get. However, this is a less secure
method as it outputs your variables to the page (twice, even though they
are hidden) and so someone could maliciously use them. I don't know how
important this is for your page, and using the $_POST makes it more
difficult for these variables to be then fiddled with and put back into
your form, but this certainly falls into the hack category. I would
recommend using a session and making everything session variables. There
are plenty of tutes out there, and some fairly good ones at
<a style='text-decoration: underline;' href="http://www.phpgeek.com" target="_blank">http://www.phpgeek.com</a> and <a style='text-decoration: underline;' href="http://www.phpbuilder.com" target="_blank">http://www.phpbuilder.com</a><!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: Yes/No Popup window