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 "&nbsp;<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

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>

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 "&nbsp;<INPUT TYPE=SUBMIT VALUE=\"Stream\" onclick=form.action=\"return dropdown(this.parts).EXTSTR\">";
	echo "&nbsp;<INPUT TYPE=SUBMIT VALUE=\"Download\" onclick=form.action=\"return dropdown(this.parts).EXTDOW\">";
	echo"</FORM>";

thanks again for your help.

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 "&nbsp;<INPUT TYPE=\"submit\" VALUE=\"Stream\" name=\"stream\">";
echo "&nbsp;<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.

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

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

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 !

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 code does 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?

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 ?

the following is from the original code:

echo "<FORM ACTION=\"\" METHOD=POST [B]onSubmit=\"return dropdown(this.parts)\"[/B]>";
	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.

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 "&nbsp;<INPUT TYPE=\"submit\" VALUE=\"Stream\" name=\"stream\">";
echo "&nbsp;<INPUT TYPE=\"submit\" VALUE=\"Download\" name=\"download\">";
echo"</FORM>";
?>
</body>
</html>

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.

Yep.. There is just an echo.. You have to add your own code to do whatever you want instead of echoing it..

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 [B]dropdown(this.parts)[/B]\">";
	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

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.

You can use isset($_POST['name of button']) to this for more details visit this blog :-
{url snipped}

Edited 4 Years Ago by diafol: Promotion of own site on a 3 year old thread

This article has been dead for over six months. Start a new discussion instead.