Jump to content

Open, save and cancel dialog box


Jude

Recommended Posts

Please help,

Im a newbie and all i can find is complex code for the wrong thing i am looking for.

All i need is a simple dialog box, i have a website whereby when the user clicks the link i want a dialog box to pop up asking the user whether they want to open, save or cancel the operation.

Although this may seem simple i have no idea where to start ive hit a mental block, as this isn't my usual programming code.

Please help its much appreciated

Many thanks
Link to comment
https://forums.phpfreaks.com/topic/33473-open-save-and-cancel-dialog-box/
Share on other sites

I asked for this not long ago, you could try searching for a post about downloading an XML file. Its basically to do with using the header function.
[code=php:0]
  header('Content-type: text/xml');

  // It will be called downloaded.xml
  header('Content-Disposition: attachment; filename="MyFilname.xml"');
[/code]
It has everything to do with it,

All she needs is a standard button that posts back to the PHP, and in there she can run the above (albiet she will need to change the content-type) and that will bring up a dialog box to open, save or cancel.

If you don't believe me here's an example,

On the opening form,

[code=php:0]
<?php

if (isset($_POST['action'])) {

// Content type of file you want them to download
header('Content-type: text/xml');

// It will be called default.xml
header('Content-Disposition: attachment; filename="default.xml"');

//
readfile("default.xml");

exit;

} else {

  $html = "<html>
          <head>
          <title>form</title>
          </head>
          <body>
          <form name='myform' method='post' action='script.php'>
          <input name='action' type='hidden' value='download' />
          <input name='mybutton' type='submit' value='Download' />
          </form>
          </body>
          </html>";

  echo $html;
}
?>
[/code]

Just wack a mock up default.xml file alongside the script and test it for yourself.
Hey guys thanks for you're help, im sure it can be done in both programming languauges, i just need the easiest i suppose as they aren't my main programming languages.

Is it easier done in javascript??

If so i dont suppose either of you guys know how to do this in javascript??

Thank you so much

:)
Put this in the header in between <head> and before </head>.

[code]
<script type="text/javascript">
//FUNCTION WRITTEN BY JUSTINK101
function new_window(w, h, url, name) {
function centerWindow(myWidth, myHeight) {
leftPos = 0
topPos = 0
if (screen) {
leftPos = (screen.width / 2) - (myWidth / 2);
topPos = (screen.height / 2) - (myHeight / 2);
}
}

function makeNewWindow(url, name, width, height, cenLeft, cenTop) {
parentWindow = window.open(url, name, 'width=' + width + ',height=' + height + ',toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=false, left=' + cenLeft + ', top=' + cenTop +'')
}

centerWindow(w, h);
makeNewWindow(url, name, w, h, leftPos, topPos);
}
</script>
[/code]


<a href="javascript:" onclick="new_window(200, 200, 'mynewpage.php', 'myWindow');">

Then simply write your PHP in that new file mynewpage.php. SHould get you started. By the way, enjoy my little niffty js function, quite nice, I use it all the time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.