我想创建一个php变量,具体取决于下拉列表中选择的内容。
这是下拉列表:
<td width="5" rowspan="2"><select id="ddlTime">
<option selected="selected" value="perhour" name="perhour">per hour</option>
<option value="perannum" name="perannum">per annum</option>
</select></td>
根据是选择“每小时”还是“每年”,我想要执行以下操作(如果这是正确的,我不太确定语法,这部分是在另一页上):
// if per hour is selected:
$result_pharmacist = $_POST["pharmacist"];
$result_dispenser = $_POST["dispenser"];
// if per annum is selected:
$user_pharmacist = $_POST["pharmacist"];
$result_pharmacist = $user_pharmacist/37.5/52;
$user_dispenser = $_POST["dispenser"];
$result_dispenser = $user_dispenser/37.5/52;
如何做到这一点?
这是我的完整形式:
<form action="<?php the_permalink(); ?>calculations" method="post">
<h2>Savings calculator</h2>
<div class="calculator-divide"></div>
<table border="0">
<tr>
<td colspan="3"><h3>Current service costs</h3></td>
</tr>
<tr>
<td width="440"><p>Pharmacist</p></td>
<td><p style="padding-left:5px!IMPORTANT;">£
<input style="width:145px!IMPORTANT;" value="22.00" type="text" name="pharmacist" />
</p></td>
<td width="5" rowspan="2"><select id="ddlTime">
<option selected="selected" value="perhour" name="perhour">per hour</option>
<option value="perannum" name="perannum">per annum</option>
</select></td>
</tr>
<tr>
<td><p>Dispenser / Technician</p></td>
<td><p style="padding-left:5px!IMPORTANT;">£
<input style="width:145px!IMPORTANT;" value="8.00" type="text" name="dispenser" />
</p></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3"><h3>Time taken to carry out manual dispensing tasks</h3></td>
</tr>
<tr>
<td><p>Measure 50mls dose by hand including Pharmacist check</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="1" type="text" name="measure-check" />
Minute(s)</p></td>
</tr>
<tr>
<td><p>Preparing labels from dispensary system</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="0.5" type="text" name="labels" />
Minute(s)</p></td>
</tr>
<tr>
<td><p>Write up CD register</p></td>
<td colspan="2"><p style="padding-left:5px!IMPORTANT;">
<input value="2" type="text" name="cd-register" />
Minute(s)</p></td>
</tr>
<tr>
<td></td>
<td colspan="3"><div class="estimate">
<input style="margin-bottom:20px;" type="submit" value="Estimate my savings" />
</div></td>
</tr>
</table>
</form>
答案 0 :(得分:2)
<select id="ddlTime" name="ddlTime">
和
if( $_POST['ddlTime']=='perhour' ){
// if per hour is selected:
$result_pharmacist = $_POST["pharmacist"];
$result_dispenser = $_POST["dispenser"];
}elseif( $_POST['ddlTime']=='perannum' ){
// if per annum is selected:
$user_pharmacist = $_POST["pharmacist"];
$result_pharmacist = $user_pharmacist/37.5/52;
$user_dispenser = $_POST["dispenser"];
$result_dispenser = $user_dispenser/37.5/52;
}
答案 1 :(得分:0)
我希望这可以帮到你:
<?php
if(isset ($_POST['save']))
{
$temp = $_POST['opsi'];
echo $temp;
}
?>
<html>
<body>
<form action="newEmptyPHP.php" method="POST">
<h3> Choose Your Option</h3>
<select name="opsi">
<option value=0 selected>- Customer -</option>
<option value="perannum" name="perannum">perannum</option>
<option value="perhour" name="perhour">perhour</option>
</select> <br> <br>
<input type="submit" name="save" value="Save and Commit">
</form>
</body>
</html>