【发布时间】:2021-11-26 05:49:32
【问题描述】:
所以我正在尝试使用 PHP 和 HTML 创建一个燃料计算器表单。在大多数情况下,我的表格非常充实,但是,我被困在一件事上。
所以我想创建一个获取用户输入的燃料津贴选项。我想向用户提出的问题是他们是否购买了杂货。如果用户输入是,那么我希望出现一个不同的输入框,询问用户他们花费的杂货数量,然后根据该输入计算燃料点。但是,我不知道如何根据他们的回答来获得最初的问题,即他们在杂货上花了多少钱。
这是我目前所拥有的:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
How many miles did you drive? <input type="text" name="milesDriven" value="<?php echo $milesDriven;?>">
<span class="error">* <?php echo $milesDrivenErr;?></span>
<br><br>
What is your cars miles per gallon?:
<input type="text" name="milesPerGallon" value="<?php echo $milesPerGallon;?>">
<span class="error">* <?php echo $milesPerGallonErr;?></span>
<br><br>
Type of gas used:
<br><br>
<input type="radio" name="gasType" <?php if (isset($gasType) && $gasType=="87 octane - 1.89$/gal") echo "checked";?> value="1.89">87 octane - 1.89$/global
<br><br>
<input type="radio" name="gasType" <?php if (isset($gasType) && $gasType=="89 octane - 1.99$/gal") echo "checked";?> value="1.99">89 octane - 1.99$/global
<br><br>
<input type="radio" name="gasType" <?php if (isset($gasType) && $gasType=="92 octane - 2.09$/gal") echo "checked";?> value="2.09">92 octane - 2.09$/global
<br><br>
<input type="text" name="groceries"
<?php
if ($groceries = "yes") {
//code here that causes the input field to appear
}else if ($groceries = "no") {
//do nothing and proceed with the calculation
}
?>
<input type="submit" name="submit" value="Submit">
</form>
您可以在 PHP 块内创建表单输入吗?如果这是一个愚蠢的问题,请原谅我。我仍然是一名初学者,正在尝试更多地了解后端编码。
【问题讨论】:
标签: php html forms user-input