我正在创建一个简单的增值税计算器,我遇到了下拉列表选项的问题。这两个选项是$ vatincluded& $ vatexcluded。如果选择$ vatincluded,则进行简单计算,如果选择$ vatexcluded,则ammount输入保持原样。我收集我需要设置一个布尔来检查是否已在下拉列表中选择$ vatincluded但不确定如何添加到脚本。任何人都可以指出我正确的方向。
非常感谢提前......
<?php
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];
$ammount = $_POST['ammount'];
$vatincluded = $_POST['vatincluded'];
$vatexcluded = $_POST['vatexcluded'];
if ($vatincluded) {
$netammount = ($ammount / 120 * 100);
}
else
{
$netammount = $ammount;
$vatammount = ($netammount * 0.20);
$grossammount = ($netammount + $vatammount);
}
echo 'Thanks for submitting the form.<br />';
echo 'Net Ammount £: ' . $netammount . '<br />';
echo 'Vat Ammount £: ' . $vatammount . '<br />';
echo 'Gross Ammount £: ' . $grossammount . '<br />';
echo 'Your first name ' . $first_name . '<br />';
echo 'Your last name: ' . $last_name . '<br />';
echo 'Your email address is ' . $email;
?>
答案 0 :(得分:1)
如果您是dropdown list
,则表示选择元素。
您可以执行以下操作:
HTML
<select name="vat">
<option value="yes">Include</option>
<option value="no">Not included</option>
</select>
PHP
if ($_POST['vat'] == 'yes') {
// vat include
} else {
// vat excluded
}