|
Posted by Joseph S. on 10/17/33 11:28
Hi,
I got a nice workaround for the original problem of multiple forms I
had:
In many cases, you want multiple submit buttons and not multiple forms
really.
So here is a sample code that works fine for the muliple submits case:
(multisubmits.php)
<?php
session_start();
?>
<html>
<head>
<title>Title</title>
</head>
<body>
<center>
<form name="taxform" action="multisubmits.php" method="POST" >
Enter Gross<br/>
<input type="text"
name="gross"
value="<?php if(isset($_SESSION['a'])){echo $_POST['gross'];}?>"
/>
<br/>
<table>
<tr>
<td><input type="submit" name="Tax30" value="30pcTax" /></td>
<td><input type="submit" name="Tax40" value="40pcTax" /></td>
<td><input type="submit" name="Tax50" value="50pcTax" /></td>
</tr>
</table>
</form>
<?php
/* doing the calculation here */
$gross = (float)$_POST["gross"];
$tax = 0;
if (isset($_POST['Tax30'])){
$tax = $gross * 0.3;
$country = "USA";
}else if(isset($_POST['Tax40'])){
$tax = $gross * 0.4;
$country = "United Kingdom";
}else if(isset($_POST['Tax50'])){
$tax = $gross * 0.5;
$country = "France";
}
?>
<br />
Tax<br/>
<?php echo $_SESSION['a'] ?><br/>
<?php if(isset($_SESSION['a'])){echo $tax;} ?><br/>
Must be <?php echo $country; ?>!<br/>
</center>
</body>
</html>
<?php $_SESSION['a'] = 1; ?>
That takes care of a lot of things - you can make forms with any
arbitrary multiple number of submit buttons and you just have to check
which submit was pressed and act accordingly!
Also, my original problem of multiple forms is also solved by session
variables. Anyways, now I deal with multiple forms like this:
<?php
session_start();
?>
<html>
<head>
<title>Title</title>
</head>
<body>
<center>
<form name="taxform" action="multiforms.php" method="GET" >
Enter Gross<br/>
<input type="text"
name="gross1"
value="<?php if(isset($_SESSION['a'])){echo $_GET['gross1'];}?>"
/><br/>
<input type="submit" name="Tax30" value="30pcTax" />
</form>
<form name="taxform" action="multiforms.php" method="GET" >
Enter Gross<br/>
<input type="text"
name="gross2"
value="<?php if(isset($_SESSION['a'])){echo $_GET['gross2'];}?>"
/><br/>
<input type="submit" name="Tax40" value="40pcTax" />
</form>
<form name="taxform" action="multiforms.php" method="GET" >
Enter Gross<br/>
<input type="text"
name="gross3"
value="<?php if(isset($_SESSION['a'])){echo $_GET['gross3'];}?>"
/><br/>
<input type="submit" name="Tax50" value="50pcTax" />
</form>
</center>
<?php
/* doing the calculation here */
$tax = 0;
if (isset($_GET['Tax30'])){
$gross = (float)$_GET["gross1"];
$tax = $gross * 0.3;
$country = "USA";
}else if(isset($_GET['Tax40'])){
$gross = (float)$_GET["gross2"];
$tax = $gross * 0.4;
$country = "United Kingdom";
}else if(isset($_GET['Tax50'])){
$gross = (float)$_GET["gross3"];
$tax = $gross * 0.5;
$country = "France";
}
?>
<br />
Tax<br/>
<?php echo $_SESSION['a'] ?><br/>
<?php if(isset($_SESSION['a'])){echo $tax;} ?><br/>
Must be <?php echo $country; ?>!<br/>
</body>
</html>
<?php $_SESSION['a'] = 1; ?>
Thanks to all,
Regards,
Joseph S.
Navigation:
[Reply to this message]
|