【发布时间】:2015-08-18 17:21:18
【问题描述】:
我正在使用这个 HTML 代码来允许用户添加更多字段并将它们从该订单表单中删除。
<!DOCTYPE HTML>
<html>
<head>
<title>Dynamic Form Processing with PHP | Tech Stream</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="css/default.css"/>
<script type="text/javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
if(rowCount < 20){ // limit the user from creating fields more than your limits
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
}
}else{
alert("Maximum Photos per order is 20.");
}
}
function deleteRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) { // limit the user from removing all the fields
alert("Cannot Remove all Picture fields.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}
</script>
</head>
<body>
<form action="process.php" class="register" method="POST">
<fieldset class="row1">
<legend>Order Details</legend>
<p>
<input type="button" value="Add Picture" onClick="addRow('dataTable')" />
<input type="button" value="Remove Picture" onClick="deleteRow('dataTable')" />
<p>(All acions apply only to entries with check marked check boxes only.)</p>
</p>
<table id="dataTable" class="form" border="1"> <!-- These Fields get duplicated -->
<tbody>
<tr>
<p>
<td><input type="checkbox" required="required" name="chk[]" checked="" /></td>
<td>
<label for="BX_file">Filename</label>
<input type="text" required="required" class="small" name="BX_file[]">
</td>
<td>
<label for="BX_gallery">Gallery</label>
<select id="BX_gallery" name="BX_gallery" required="required">
<option>....</option>
<option>Nature</option>
<option>Stilllife</option>
<option>Portrait</option>
<option>Constructed</option>
<option>Nature</option>
<option>Black & White </option>
<option>Rotarian Dinner Dance 25/04/2015</option>
</select>
</td>
<td>
<label for="BX_medium">Medium</label>
<select id="BX_medium" name="BX_medium" required="required">
<option>....</option>
<option>Small Print</option>
<option>Medium Print</option>
<option>Large Print</option>
<option>Custom Print</option>
<option>CD Image Disc</option>
<option>Digital Download</option>
</select>
</td>
<td>
<label for="BX_quantity">Quantity</label>
<input type="number" required="required" class="small" name="BX_quantity[]">
</td>
</p>
</tr>
</tbody>
</table> <!-- End of Fields that are duplicated. -->
<fieldset class="row2">
<legend>Terms and Mailing</legend>
<p class="agreement">
<input type="checkbox" value=""/>
<label>* I accept the <a href="#">Terms and Conditions</a></label>
</p>
<div class="clear"></div>
</fieldset>
<fieldset class="row3">
<legend>Other</legend>
<p class="notes">
<input type="text">
<label>Additional Notes</label>
</p>
<div class="clear"></div>
</fieldset>
<input class="submit" type="submit" value="Confirm »" />
<div class="clear"></div>
</fieldset>
</form>
</body>
</html>
我现在正在尝试通过 PHP 处理字段输入,以便可以通过电子邮件将它们发送给我。但是我似乎无法让它工作。谁能指出我的 PHP 代码哪里出错了?
<?php
$str_File = $_POST['BX_FILE'];
$str_Gall = $_POST['BX_GALLERY'];
$str_Med = $_POST['BX_MEDIUM'];
$int_Quant = $_POST['BX_QUANT'];
$str_Notes = $_POST['NOTES'];
//Gets all the values and saves them to the variables in array format.
$int_Num = count($FILE) //Gets the size of th array.
for ($x = 1; $x <= $int_Num; $x++) {
$str_ORD = "Order Field: $x, Filename: $str_File[$x], Gallery: $str_Gall[$x], Photo Medium: $str_Med[$x], Quantity: $int_Quant[$x]"
}
//Loops through all the arrays assembling the message for the email.
mail("harrysanderson@live.co.uk","Order Test",$str_ORD)
//Sends email.
This是我一直关注的教程:
非常感谢任何帮助! 抱歉,我是 PHP 的初学者。
【问题讨论】:
-
“似乎无法正常工作”是什么意思?它是如何失败的?
-
如果
$FILE是指超全局变量,它就是$_FILES -
它失败了,因为没有发送电子邮件,而是页面更改,以便您可以看到 PHP 代码。抱歉,$str_File 仅用于保存 HTML 表单中的值。
标签: javascript php jquery html debugging