PDA

View Full Version : submit forms alternative



sftl99
Jul 26th, 2005, 05:50 PM
I have a form <form name="rmaform" method="post" action="print.php">
I want two "submit" buttons, one that goes to print.php and one that goes to email.php. Is this possible?

hourang
Jul 26th, 2005, 07:24 PM
something like this. theres many ways to do it.

<script>
function submitform(){
if (document.theform.submitbutton.value == "Submit"){
document.theform.action = "submit.php";
document.theform.submit();
} else {
document.theform.action = "print.php";
document.theform.submit();
}
}
</script>

<form name="theform" method="POST" action="submit.php" onSubmit="submitform();">
<input type="submit" name="submitbutton" value="Submit">
<input type="submit" name="submitbutton" value="Print">
</form>

sftl99
Jul 26th, 2005, 10:55 PM
Thanks. That didn't work, perhaps because I'm calling a bunch of different functions, but I took your code and just made a button out of it:
<input name="submitbutton" type="button" class="sbttn" id="submitbutton" value="Email RMA" onClick="document.rmaform.action='rmaemail.php';document.rmaform.submit();">
It works. Thank you.

glenngv
Jul 27th, 2005, 07:26 AM
This is better:


<form name="theform" method="POST" action="print_or_email.php">
<input type="submit" name="btnPrint" value="Print" onclick="this.form.action='print.php'" />
<input type="submit" name="btnEmail" value="Email" onclick="this.form.action='email.php'" />
</form>

For javascript disabled browsers, print_or_email.php should redirect (including post data) to corresponding php based from the clicked button.

sftl99
Jul 27th, 2005, 05:07 PM
just logged on this morning and saw this. this DOES work better and more universally. thanks a ton!

hourang
Jul 27th, 2005, 05:41 PM
my bad, i thought you could use the same submit names in javascript. you could also do something like this quick script i wrote if you want to process different things after different buttons are pressed:


<script>
<!--
function submitform(strButton){
switch (strButton) {
case "submit":
//call and process validation
//other scripts can be put here
document.theform.action = "submit.php";
document.theform.submit();
break;
case "print":
document.theform.action = "print.php";
document.theform.submit();
break;
}
}
// -->
</script>

<form name="theform" method="POST" action="submit.php">
<input type="submit" name="submitbutton" onClick="submitform('submit');" value="Submit">
<input type="submit" name="submitbutton2" onClick="submitform('print');" value="Print">
</form>

glenngv
Jul 28th, 2005, 04:40 AM
my bad, i thought you could use the same submit names in javascript.Generally you could do that on any form control. The result will be an array or collection of those controls with the same name.




<script>
<!--
function submitform(strButton){
switch (strButton) {
case "submit":
//call and process validation
//other scripts can be put here
document.theform.action = "submit.php";
document.theform.submit();
break;
case "print":
document.theform.action = "print.php";
document.theform.submit();
break;
}
}
// -->
</script>

<form name="theform" method="POST" action="submit.php">
<input type="submit" name="submitbutton" onClick="submitform('submit');" value="Submit">
<input type="submit" name="submitbutton2" onClick="submitform('print');" value="Print">
</form>The submit button already submits the form, you should not call the submit() method anymore.