the_maxx Posted April 24, 2007 Share Posted April 24, 2007 Hi there I´m returning to work on php as amateur after years of hiatus. I´m having an issue with coding the submit button to do something. Whenever I want to use it to do something, there is an original page (in html) with the form in it, and once you press the button, the target parameter of form sends me to the next page, which is the one page I put the php code. But I want to stop doing this; I want a button to work on the same page as it is, without calling a next page with the code. For example, this is what I want to do; a page to download files, where you radio select an option out of three for example, press the submit button, and what I want to happen is that this button calls the windows download dialogue box on the spot, for the user to just click "accept" and download a file. Much like this: (*) Option 1 ( ) Option 2 ( ) Option 3 [Download selected file] <----- Submit button If anyone knows how to, please lend me a hand. I pressume it can be done calling a function already coded at the start of the page; or perhaps the function can be coded on a txt file and call it; but dont know how to do it. Link to comment https://forums.phpfreaks.com/topic/48509-submit-function-help/ Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 change your action to <?php print $_SERVER['PHP_SELF']; ?> then before your form put: if(isset($_POST['Submit'])){ //Do your form processing here } else { //Display the form } Link to comment https://forums.phpfreaks.com/topic/48509-submit-function-help/#findComment-237288 Share on other sites More sharing options...
the_maxx Posted April 24, 2007 Author Share Posted April 24, 2007 Thanks for the answer, lets see if I understand correctly. My page is .html so the code will be like this: (please tell me if its ok) <html> <?php if(isset($_POST['Submit'])){ // My download code } else { ?> <form action="<?php print $_SERVER['PHP_SELF']; ?>"> <?php } ?> </html> Link to comment https://forums.phpfreaks.com/topic/48509-submit-function-help/#findComment-237304 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 Yes that is corrent, HOWEVER, you need to give your file the .php extension - this does not affect HTML code in anyway, UNLESS your server knows to parse .html files as php files Link to comment https://forums.phpfreaks.com/topic/48509-submit-function-help/#findComment-237306 Share on other sites More sharing options...
the_maxx Posted April 24, 2007 Author Share Posted April 24, 2007 it still doesn't work, it just reloads the same page. This is my complete code, perhaps I misses something (I already change it to .php) : <html><head><title>download test</title></head> <body> <br><br><br> <?php if(isset($_POST['Submit'])){ if ($radio1 == '1') { echo "file01.zip"; } if ($radio1 == '2') { echo "file02.zip"; } } else { ?> <FORM ENCTYPE="multipart/form-data" ACTION="<?php print $_SERVER['PHP_SELF']; ?>" METHOD="post"> <input TYPE="radio" VALUE='1' NAME="radio1"> Zip File 01<br> <input TYPE="radio" VALUE='2' NAME="radio1"> Zip File 02<br><br> <INPUT TYPE="submit" VALUE="Download File"> </FORM> <?php } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/48509-submit-function-help/#findComment-237325 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 <INPUT TYPE="submit" VALUE="Download File"> change to <INPUT TYPE="submit" name="Submit" VALUE="Download File"> NOTE: Capital 'S' in submit for name Link to comment https://forums.phpfreaks.com/topic/48509-submit-function-help/#findComment-237331 Share on other sites More sharing options...
the_maxx Posted April 24, 2007 Author Share Posted April 24, 2007 Right you were, thank you very much. I just realized the code for download I had was just the name of the file, that worked fine when it was from one page to another, but here, it ends up displaying just the name typed on screen. Guess I'll have to search for a good download code Link to comment https://forums.phpfreaks.com/topic/48509-submit-function-help/#findComment-237345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.