这是一个较大项目的很小版,仅供说明。禁用的计算字段值“ applet”未显示在要发送的电子邮件中。有什么想法为什么以及如何做到这一点?
<body>
<form name="fruit" id= "fruit" action="acknowlfruit.php" method="post"
target="_self">
<fieldset>
<table onkeyup="computeAll()">
<tr><th>Fruit</th><th>No.</th><th>Price</th><th>Total</th></tr>
<tr><td> <label for ="apples" class="label">Apples:</label></td>
<td> <input id= "apples" name="apples" type="text" required class="input"
value="0" size="3" maxlength="3" indent= "250px" /> </td>
<td>at 5p</td>
<td><input id="appletot" type = "text" class= "input" value="0" size="5"
maxlength="10" disabled/></td></tr>
</table>
<br/>
</p>
<script type="text/javascript">
function computeAll() {
document.fruit.appletot.value = 5*document.fruit.apples.value;
}
</script>
<input name="submit" type="submit" value="Submit" />
</body>
</html>
<?php
if (isset($_POST['submit'])){
$to = 'myemail@gmail.com';
$subject = 'Fruit Cost';
$message .= 'Apples: '.$_POST['apples']." ";
$message .= 'Cost of apples: '.$_POST['applestot']."\r\n\r\n";
$success = mail($to, $subject,$message, $headers);
}
?>
答案 0 :(得分:0)
disabled
字段未传递到服务器。使用type="hidden"
或什至在服务器端计数总数:
if (isset($_POST['submit'])){
$to = 'myemail@gmail.com';
$subject = 'Fruit Cost';
$message .= 'Apples: '.$_POST['apples']." ";
$message .= 'Cost of apples: '.($_POST['apples'] * 5)."\r\n\r\n";
$success = mail($to, $subject,$message, $headers);
}
第二种方法更安全,因为用户可以更改客户端JavaScript,例如使用:
function computeAll() {
document.fruit.appletot.value = 0.5 * document.fruit.apples.value;
}
在这种情况下,您将如何找到错误?