VAT计算器的布尔值

时间:2011-11-15 21:00:27

标签: php boolean

我正在创建一个简单的增值税计算器,我遇到了下拉列表选项的问题。这两个选项是$ 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 &pound;: ' . $netammount  . '<br />';
  echo 'Vat Ammount &pound;: ' . $vatammount . '<br />';
  echo 'Gross Ammount &pound;: ' . $grossammount . '<br />';
  echo 'Your first name ' . $first_name . '<br />';
  echo 'Your last name: ' . $last_name . '<br />';
  echo 'Your email address is ' . $email;
?>

1 个答案:

答案 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
}