0
我一直有一些嚴重的問題讓我的表單正常工作。首先是PHP計算(attireCalculate.php),然後是PHP處理文件(processAttire.php),最後是我的XHTML(attireForm.php)。對不起,這一切多久,但我一遍遍地瀏覽它,並遍佈網絡無濟於事。我找不到問題。當我點擊提交按鈕時沒有任何反應。PHP表格 - 有問題
我應該提到,我是編程和PHP的新手,所以可能是因爲我缺少的東西其實很簡單。謝謝你的幫助。對此,我真的非常感激。
attireCalculate.php
<?php
function message($ramHatQ, $teemoHatQ, $blitzHoodieQ, $galioHoodieQ, $datAsheQ, $graggyIceQ)
{
$cost = sprintf("%.2lf", calculateCost($ramHatQ, $teemoHatQ, $blitzHoodieQ, $galioHoodieQ, $datAsheQ, $graggyIceQ));
$tax = sprintf("%.2lf", calculateTax($cost));
$total = sprintf("%.2lf", calculateTotal($cost, $tax));
$text = "<h1>Product Summary</h1>".
"<h3>The cost of items selected is $".$cost.".<br />".
"The tax applied is $".$tax.".<br />".
"Therefore, the total cost is $".$total.".</h3>";
return $text;
}
function calculateCost($ramHatQ, $teemoHatQ, $blitzHoodieQ, $galioHoodieQ, $datAsheQ, $graggyIceQ)
{
return ($ramHatQ+$teemoHatQ)*14.99+($blitzHoodieQ+$galioHoodieQ)*24.99+($datAsheQ+$graggyIceQ)*19.99;
}
function calculateTax($cost)
{
return $cost*0.075;
}
function calculateTotal($cost, $tax)
{
return $cost+$tax;
}
function mailSummary($email, $message)
{
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "From: EMAIL\r\n";
mail($email, "Product Summary from Riot Store Online", $message, $header);
}
?>
這裏是processAttire.php文件。我評論了免稅的一點,因爲如果我甚至無法讓事情繼續發揮作用,那麼真的沒有任何意義!
<?php
include 'attireCalculate.php';
$message = message($_POST['ramHatQ'], $_POST['teemoHatQ'], $_POST['blitzHoodieQ'], $_POST['galioHoodieQ'], $_POST['datAsheQ'], $_POST['graggyIceQ']);
echo $message;
if ($_POST['wantMail'])
{
mailSummary ($_POST['email'], $message);
echo "<h2>A summary has been sent to you via e-mail.</h2>";
}
/*
if ($_POST['taxExemptStatus'])
{
calculateCost($ramHatQ, $teemoHatQ, $blitzHoodieQ, $galioHoodieQ,
$datAsheQ, $graggyIceQ);
echo "<h2>Your tax-exempt status has been taken into account. Tax has been deducted from total cost.</h2>";
}
else
calculateTax($totalCost);
*/
?>
這裏是XHTML:
<form id="attireForm" onsubmit="return validateAttireForm()"
action="scripts/processAttire.php" method="post">
<fieldset>
<legend>Headwear</legend>
<table id="attireTable" summary="Headwear">
<tr>
<td>Rammus Hat</td>
<td>$14.99</td>
<td><label for="ramHatType">Type: </label></td>
<td><select id="ramHatType" name="ramHatType">
<option>Original</option>
<option>Ninja</option>
</select></td>
<td><label for="ramHatQ">Quantity: </label></td>
<td><input id="ramHatQ" type="text" name="ramHatQ" size="1" value="0" /></td>
</tr>
<tr>
<td>Teemo Hat</td>
<td>$14.99</td>
<td></td>
<td></td>
<td><label for="teemoHatQ">Quantity: </label></td>
<td><input id="teemoHatQ" type="text" name="teemoHatQ" size="1" value="0" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Hoodies</legend>
<table id="attireTable" summary="Hoodies">
<tr>
<td>Blitzcrank Hoodie</td>
<td>$24.99</td>
<td><label for="blitzHoodieQ">Quantity: </label></td>
<td><input id="blitzHoodieQ" type="text" name="blitzHoodieQ" size="1" value="0" /></td>
</tr>
<tr>
<td>Galio Hoodie</td>
<td>$24.99</td>
<td><label for="galioHoodieQ">Quantity: </label></td>
<td><input id="galioHoodieQ" type="text" name="galioHoodieQ" size="1" value="0" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>T-Shirts</legend>
<table id="attireTable" summary="T-Shirts">
<tr>
<td>"Dat Ashe" T-Shirt</td>
<td>$19.99</td>
<td><label for="datAsheQ">Quantity: </label></td>
<td><input id="datAsheQ" type="text" name="datAsheQ" size="1" value="0" /></td>
</tr>
<tr>
<td>"Graggy Ice" T-Shirt</td>
<td>$19.99</td>
<td><label for="graggyIceQ">Quantity: </label></td>
<td><input id="graggyIceQ" type="text" name="graggyIceQ" size="1" value="0" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Record?</legend>
<table summary="Record?">
<tr>
<td><label for="wantMail">Would you like a record sent to you by e-mail? </label></td>
<td><input id="wantMail" type="checkbox" name="wantMail" value="yes" /></td>
</tr>
<tr>
<td><label for="email">E-mail Address: </label></td>
<td><input id="email" type="text" name="email" size="25" /></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Processing</legend>
<table summary="Processing">
<tr>
<td><label for="taxExemptStatus">Do you have tax-exempt status? </label></td>
<td><input id="taxExemptStatus" type="checkbox" name="taxExemptStatus" value="yes" /></td>
</tr>
<tr>
<td><input type="submit" value="Add to Cart" /></td>
<td><input id="resetAttire" type="reset" value="Reset Selections" /></td>
</tr>
</table>
</fieldset>
</form>
這裏是包含validateAttireForm()的JavaScript文件:
//attireValidate.js
function validateAttireForm()
{
var attireFormObj = document.getElementById("attireForm")
var ramHatQ = attireFormObj.ramHatQ.value;
var teemoHatQ = attireFormObj.teemoHatQ.value;
var blitzHoodieQ = attireFormObj.blitzHoodieQ.value;
var galioHoodieQ = attireFormObj.galioHoodieQ.value;
var datAsheQ = attireFormObj.datAsheQ.value;
var graggyIceQ = attireFormObj.graggyIceQ.value;
var email = attireFormObj.email.value;
var quantities = new Array(ramHatQ, teemoHatQ, blitzHoodieQ, galioHoodieQ, datAsheQ, graggyIceQ);
for (q in quantities)
{
quantityOK = validateQuantity(quantities[q]);
if (quantityOK = false)
{
break;
}
}
if (attireFormObj.wantMail.checked)
emailOK = validateEmail(email);
else
emailOK = true;
return quantityOK && emailOK;
}
function validateQuantity(quantity)
{
if (isNaN(quantity))
{
alert("Error: One or more quantities are abnormal. Please input a number for quantity.")
return false;
}
if (quantity < 0 || quantity > 100)
{
alert("Error: Quantity must be in the range 0-100 units.")
return false;
}
return true;
}
function validateEmail(address)
{
var p = address.search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})$/);
if (p == 0)
return true;
else
{
alert("Error: Invalid e-mail address.")
return false;
}
}
您的表單被設置爲依賴於名爲'validateAttireForm()'的函數的結果,但我在代碼中的任何位置都看不到此函數。你忘記發佈了嗎?還是你沒有定義它? – SquareCat
它是JavaScript文件的一部分。這會對PHP文件有什麼影響嗎? –
打開php錯誤,看看會發生什麼。另外,什麼是'validateAttireForm'? – putvande