Multiple Submit Buttons in Form
hi
i have the following complication. i have created a form which contains a drop-down list and a submit-button, which streams the file selected in the list. recently, i have been asked to add a download option, and the logical step would be to add a 'download'-submit button as well, which would do the same action, but should link to the mp3-counterpart of the selected part.
is it possible to have more than one submit-button in a single form (with different actions), without linking to outside scripts? if yes, how? and if not, how would i accomplish this with an outside script?
here is the current form:
<?php
define("DIR", "other/");
define("FILENAME", "Name");
echo "<FORM ACTION=\"\" METHOD=POST onSubmit=\"return dropdown(this.parts)\">";
echo "<select name=\"parts\"><option value=\"\"> - Select Part - </option>";
$file = DIR.FILENAME."01.ram";
echo "<option value=$file>Part 1</option>";
$file = DIR.FILENAME."02.ram";
echo "<option value=$file>Part 2</option>";
$file = DIR.FILENAME."03.ram";
echo "<option value=$file>Part 3</option>";
$file = DIR.FILENAME."04.ram";
echo "<option value=$file>Part 4</option>";
$file = DIR.FILENAME."05.ram";
echo "<option value=$file>Part 5</option>";
echo "</select>";
echo " <INPUT TYPE=SUBMIT VALUE=\"Stream!\">";
echo"</FORM>";
this is really important to me, so any help is much appreciated.
best regards & thanks in advance
pygmalion
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
Possible. Here is an example.
<html>
<body>
<form method="post" name="form">
<input type="submit" name="submit" value="page1" onclick="form.action='page1.php';">
<input type="submit" name="submit" value="page2" onclick="form.action='page2.php';">
</form>
</body>
</html>
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
thanks for your spontaneous answer. i have tried to incorporate my intended actions into your system, but it doesn't seem to function. what am i doing wrong?
here's my code:
<?php
define("DIR", "other/");
define("FILENAME", "Name");
define("EXTSTR", "ram");
define("EXTDOW", "mp3");
echo "<FORM NAME=\"form\" ACTION=\"\" METHOD=\"post\">";
echo "<select name=\"parts\"><option value=\"\"> - Select Part - </option>";
$file = DIR.FILENAME."01.";
echo "<option value=$file>Part 1</option>";
$file = DIR.FILENAME."02.";
echo "<option value=$file>Part 2</option>";
$file = DIR.FILENAME."03.";
echo "<option value=$file>Part 3</option>";
$file = DIR.FILENAME."04.";
echo "<option value=$file>Part 4</option>";
$file = DIR.FILENAME."05.";
echo "<option value=$file>Part 5</option>";
echo "</select>";
echo " <INPUT TYPE=SUBMIT VALUE=\"Stream\" onclick=form.action=\"return dropdown(this.parts).EXTSTR\">";
echo " <INPUT TYPE=SUBMIT VALUE=\"Download\" onclick=form.action=\"return dropdown(this.parts).EXTDOW\">";
echo"</FORM>";
thanks again for your help.
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
I believe this is what you are trying to do. Depending upon which button the user clicks, you either let him download the song with an mp3 extension, or, stream the song with ram extension ? If thats right, why not do the processing after he submits the form ? That is,
<?php
define("DIR", "other/");
define("FILENAME", "Name");
define("EXTSTR", "ram");
define("EXTDOW", "mp3");
if(isset($_POST['stream'])) {
echo "Streaming ".$_POST['parts'].EXTSTR;
}
if(isset($_POST['download'])) {
echo "Download ".$_POST['parts'].EXTDOW;
}
echo "<FORM NAME=\"form\" METHOD=\"post\" action=\"test.php\">";
echo "<select name=\"parts\"><option value=\"\"> - Select Part - </option>";
$file = DIR.FILENAME."01.";
echo "<option value=$file>Part 1</option>";
$file = DIR.FILENAME."02.";
echo "<option value=$file>Part 2</option>";
$file = DIR.FILENAME."03.";
echo "<option value=$file>Part 3</option>";
$file = DIR.FILENAME."04.";
echo "<option value=$file>Part 4</option>";
$file = DIR.FILENAME."05.";
echo "<option value=$file>Part 5</option>";
echo "</select>";
echo " <INPUT TYPE=\"submit\" VALUE=\"Stream\" name=\"stream\">";
echo " <INPUT TYPE=\"submit\" VALUE=\"Download\" name=\"download\">";
echo"</FORM>";
?>
I hope this is what you are looking for!
Edit: Oops! I don't know what the javascript function dropdown does. But you can have an onsubmit event at the form tag and do the same.
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
Edit: Oops! I don't know what the javascript function dropdown does. But you can have an onsubmit event at the form tag and do the same.
I understand what you mean here, but i don't see how i can put the condition in the form-tag. can you help me with that please?
very much appreciated
pygmalion
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
What does your javascript function do btw ? Can you post it here ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
What does your javascript function do btw ? Can you post it here ?
[sorry for the delay in answering, had a few issues these last few days.]
actually, no javascript function is called, instead the submit just returns the file-name associated with the selected option in the dropdown-list.
so how can I actually put the condition to differentiate in the form-tag?
Again, much appreciated
pygmalion
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
If it just returns the filename associated with the selected option in the dropdown list, then the code I posted above should work for you !
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
If it just returns the filename associated with the selected option in the dropdown list, then the code I posted above should work for you !
hi again.
your codedoes work. i'm just not sure how to 'implement' -if you will- the return-statement in your if-statement. do you see what i mean?
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
i'm just not sure how to 'implement' -if you will- the return-statement in your if-statement. do you see what i mean?
What do you mean by return statement in if statement ? Can you post an example to show what you actually meant by that ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
the following is from the original code:
echo "<FORM ACTION=\"\" METHOD=POST <strong>onSubmit=\"return dropdown(this.parts)\"</strong>>";
echo "<select name=\"parts\"><option value=\"\"> - Select Part - </option>";
how can i implement the onSubmit in your if-statement, that should be performed after a button has been clicked.
i realize this is more of a syntax question, but it's nonetheless an essential element in making this work.
thanks again for all your quick answers.
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
You mean like this ?
<html>
<head>
<script type="text/javascript">
function dropdown(dropdown) {
if(dropdown.value == "") {
alert("Nothing selected..");
return false;
} else {
alert(dropdown.value);
return true;
}
}
</script>
</head>
<body>
<?php
define("DIR", "other/");
define("FILENAME", "Name");
define("EXTSTR", "ram");
define("EXTDOW", "mp3");
if(isset($_POST['stream'])) {
echo "Streaming ".$_POST['parts'].EXTSTR;
}
if(isset($_POST['download'])) {
echo "Download ".$_POST['parts'].EXTDOW;
}
echo "<FORM NAME=\"form\" METHOD=\"post\" onSubmit=\"javascript: return dropdown(this.parts);\" action=\"file.php\">";
echo "<select name=\"parts\"><option value=\"\"> - Select Part - </option>";
$file = DIR.FILENAME."01.";
echo "<option value=$file>Part 1</option>";
$file = DIR.FILENAME."02.";
echo "<option value=$file>Part 2</option>";
$file = DIR.FILENAME."03.";
echo "<option value=$file>Part 3</option>";
$file = DIR.FILENAME."04.";
echo "<option value=$file>Part 4</option>";
$file = DIR.FILENAME."05.";
echo "<option value=$file>Part 5</option>";
echo "</select>";
echo " <INPUT TYPE=\"submit\" VALUE=\"Stream\" name=\"stream\">";
echo " <INPUT TYPE=\"submit\" VALUE=\"Download\" name=\"download\">";
echo"</FORM>";
?>
</body>
</html>
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
ok, this is working now, but when playing the file, he does not know the extension.
so the problem remains: the if-statement works only to display (echo) what file is playing (specific extension), but it doesn't actually play the file with the specific extension.
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
Yep.. There is just an echo.. You have to add your own code to do whatever you want instead of echoing it..
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
exactly, so that's the problem. i know what i want it to do, i just don't know how i can do it from outside the form-tag.
to sum up, what i had (working) before:
echo "<FORM ACTION=\"\" METHOD=POST onSubmit=\"return <strong>dropdown(this.parts)</strong>\">";
echo "<select name=\"parts\"><option value=\"\"> - Select Part - </option>";
<SCRIPT TYPE="text/javascript">
<!--
function dropdown(mySel)
{
var myWin, myVal;
myVal = mySel.options[mySel.selectedIndex].value;
if(myVal)
{
if(mySel.form.target)myWin = parent[mySel.form.target];
else myWin = window;
if (! myWin) return true;
myWin.location = myVal;
}
return false;
}
//-->
</SCRIPT>
this would just stream the selected file. now, to do this outside of the form-tag doesn't seem to work. would you know how that can be done?
much appreciated
pygmalion
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1
umm.. I am sorry my friend ! This is all I know :(
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
umm.. I am sorry my friend ! This is all I know :(
that's no problem. thanks so much for your continuous efforts.
anyone else got any idea? it's of quite an importance to me to make this work.
pygmalion
Junior Poster in Training
71 posts since Dec 2006
Reputation Points: 12
Solved Threads: 1