Jump to content

Submit function help


the_maxx

Recommended Posts

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

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

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

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

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.