Using 2 submit buttons? How?
Moderator: General Moderators
Using 2 submit buttons? How?
Hi All,
I have a complex/lengthy finance appliction form, and I have split it into 4 pages to make it more user-friendly.
However, I also want to have 2submit buttons.
1. Will save the data and go to the next paart of the app form
2. Will save the data and exit.
How do I achieve this?
I have a complex/lengthy finance appliction form, and I have split it into 4 pages to make it more user-friendly.
However, I also want to have 2submit buttons.
1. Will save the data and go to the next paart of the app form
2. Will save the data and exit.
How do I achieve this?
Assign names to each of the submit buttons (saveexit, savecontinue?) then use php to determine which one was pressed.
For example, assume there is a form with two submit buttons. One is named saveexit, the other savecontinue. Here's what you'd do:
Let me know if you need me to elaborate.
For example, assume there is a form with two submit buttons. One is named saveexit, the other savecontinue. Here's what you'd do:
Code: Select all
if ($_POST['saveexit']) {
// code to execute if the save and exit button was pressed
}
elseif ($_POST['savecontinue']) {
// code to execute if the save and continue button was pressed
}how to do it
two different submit buttons two different names. When you write the script you'd simply use an if statment on the page that processes the data.
Code: Select all
<?php
if ($_POST['submit'] == "name1")
{
//save the data and go to the next paart of the app form
}
if ($_POST['submit'] == "name2")
{
// save the data and exit.
}
?>one submit button, two different values for them then do the if statement in php code.
Code: Select all
<?php
if(isset($_POST['button']) && ($_POST['button']=="save"))
echo "button pressed was save";
elseif(isset($_POST['button']) && ($_POST['button'] == "exit"))
echo "button pressed was exit";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form action="buttonpressed.php" method="post">
<input type="submit" name="button" value="save" />
<input type="submit" name="button" value="exit" />
</form>
</body>
</html>Myself:
But what I meant to say was two different "values" with the same "name".
Similar to phpscott:
What I said was wrong.]two different submit buttons two different names. When you write the script you'd simply use an if statment on the page that processes the data.
Similar to phpscott:
Code: Select all
<?php
<html>
<head>
</head>
<body>
<?php
if ($_POST['submit'] == "submit1")
{
echo "less money";
//save the data and go to the next paart of the app form
}
if ($_POST['submit'] == "submit2")
{
// save the data and exit.
echo "more money";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="submit" name="submit" value="submit1">
<input type="submit" name="submit" value="submit2">
</form>
</body>
</html>
?>OK, I have this:
It seems to redirect me to my root directory whichever button I press?? Probably something simple. The database is being updated so I know the SQL works. The fact that it is redirecting is also pretty promising. The 2 files which it is directing to are also both in the root directory.
Any ideas?
Code: Select all
if(!$error_msg && $_POST['submit'] == "Next >>")
{
$redirect == "loan2.php";
mysql_select_db($database_pdb_conn, $link);
$result=mysql_query("insert into secure_loan (forename_1, forename_2, surname_1, surname_2, title_1, title_2, maiden_1, maiden_2, dob_1,
dob_2, address, howlongYY, howlongMM, housetype, marital, hometel, mobtel, prev_address1, prev_address2)
values
( '".$_POST['forename1']."' , '".$_POST['forename2']."' , '".$_POST['surname1']."' , '".$_POST['surname2']."' ,
'".$_POST['title1']."' ,'".$_POST['title2']."' ,'".$_POST['maiden1']."' ,'".$_POST['maiden2']."' ,'".$_POST['dob1']."',
'".$_POST['dob2']."' ,'".$_POST['address']."' ,'".$_POST['howlongYY']."' ,'".$_POST['howlongMM']."' ,
'".$_POST['housetype']."' ,'".$_POST['marital']."' ,'".$_POST['hometel']."' ,'".$_POST['mobtel']."' ,
'".$_POST['prevaddress1']."' ,'".$_POST['prevaddress2']."')") or die(mysql_error());
header("Location: ".$redirect.SID);
}
if(!$error_msg && $_POST['submit'] == "Save & Exit")
{
$redirect =="thankyou.php";
mysql_select_db($database_pdb_conn, $link);
$result=mysql_query("insert into secure_loan (forename_1, forename_2, surname_1, surname_2, title_1, title_2, maiden_1, maiden_2, dob_1,
dob_2, address, howlongYY, howlongMM, housetype, marital, hometel, mobtel, prev_address1, prev_address2)
values
( '".$_POST['forename1']."' , '".$_POST['forename2']."' , '".$_POST['surname1']."' , '".$_POST['surname2']."' ,
'".$_POST['title1']."' ,'".$_POST['title2']."' ,'".$_POST['maiden1']."' ,'".$_POST['maiden2']."' ,'".$_POST['dob1']."',
'".$_POST['dob2']."' ,'".$_POST['address']."' ,'".$_POST['howlongYY']."' ,'".$_POST['howlongMM']."' ,
'".$_POST['housetype']."' ,'".$_POST['marital']."' ,'".$_POST['hometel']."' ,'".$_POST['mobtel']."' ,
'".$_POST['prevaddress1']."' ,'".$_POST['prevaddress2']."')") or die(mysql_error());
header("Location: ".$redirect.SID);
}Any ideas?
its ok I figured it out. I had
instead of
Thanks anyway
Code: Select all
$redirect == "page.php";Code: Select all
$redirect = "page.php";what is the value of
?
does the location actually say thanky.php?somename=somevalue;?
what is SID?
Code: Select all
<?php
header("Location: ".$redirect.SID);
?>does the location actually say thanky.php?somename=somevalue;?
what is SID?