我在尝试建立一个BMI计算器。这应该允许人们使用公制或帝国式的测量。
我意识到我可以使用隐藏的标记来解决我的问题,但这之前一直困扰着我,所以我想我会问:我可以使用$_POST['variableName']来找到提交的variableName字段-值;但是.我不知道,也不知道如何验证使用哪个表单来提交变量。
我的代码如下(虽然我不确定它是否严格地与问题相关):
<?php
$bmiSubmitted = $_POST['bmiSubmitted'];
if (isset($bmiSubmitted)) {
$height = $_POST['height'];
$weight = $_POST['weight'];
$bmi = floor($weight/($height*$height));
?>
<ul id="bmi">
<li>Weight (in kilograms) is: <span><?php echo "$weight"; ?></span></li>
<li>Height (in metres) is: <span><?php echo "$height"; ?></span></li>
<li>Body mass index (BMI) is: <span><?php echo "$bmi"; ?></span></li>
</ul>
<?php
}
else {
?>
<div id="formSelector">
<ul>
<li><a href="#metric">Metric</a></li>
<li><a href="#imperial">Imperial</a></li>
</ul>
<form name="met" id="metric" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="form/multipart">
<fieldset>
<label for="weight">Weight (<abbr title="Kilograms">kg</abbr>):</label>
<input type="text" name="weight" id="weight" />
<label for="height">Height (<abbr title="metres">m</abbr>):</label>
<input type="text" name="height" id="height" />
<input type="hidden" name="bmiSubmitted" id="bmiSubmitted" value="1" />
</fieldset>
<fieldset>
<input type="reset" id="reset" value="Clear" />
<input type="submit" id="submit" value="Submit" />
</fieldset>
</form>
<form name="imp" id="imperial" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="form/multipart">
<fieldset>
<label for="weight">Weight (<abbr title="Pounds">lbs</abbr>):</label>
<input type="text" name="weight" id="weight" />
<label for="height">Height (Inches):</label>
<input type="text" name="height" id="height" /
<input type="hidden" name="bmiSubmitted" id="bmiSubmitted" value="1" />
</fieldset>
<fieldset>
<input type="reset" id="reset" value="Clear" />
<input type="submit" id="submit" value="Submit" />
</fieldset>
</form>
<?php
}
?>我验证了它是否有效(虽然目前没有验证,但-I不想过多地干扰我的问题);我已经添加了表单,但还没有为帝国添加处理。
发布于 2009-05-10 20:13:37
要标识提交的表单,可以使用:
表单的名称不会作为帖子数据的一部分发送到服务器。
您可以按以下方式使用代码:
<form name="myform" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="frmname" value=""/>
</form>发布于 2013-02-19 13:13:04
你可以这样做:
<input type="text" name="myform[login]">
<input type="password" name="myform[password]">检查已张贴的值
if (isset($_POST['myform'])) {
$values = $_POST['myform'];
// $login = $values['login'];
// ...
}发布于 2009-05-10 20:12:27
未提交表单名称。您应该在每个表单中添加一个隐藏字段,并将其称为一天。
https://stackoverflow.com/questions/846020
复制相似问题