我使用下面的脚本在表单中添加动态行。
<TITLE> Add/Remove dynamic rows in HTML table </TITLE>
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
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;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
function deleteRow(tableID) {
try {
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) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<TABLE id="dataTable" width="350px" border="1">
<TR>
<TD><INPUT type="checkbox" name="chk[]"/></TD>
<TD><INPUT type="text" name="txt[]"/></TD>
<TD>
<SELECT name="country[]">
<OPTION value="in">India</OPTION>
<OPTION value="de">Germany</OPTION>
<OPTION value="fr">France</OPTION>
<OPTION value="us">United States</OPTION>
<OPTION value="ch">Switzerland</OPTION>
</SELECT>
</TD>
<TD><INPUT type="text" name="passport[]"/></TD>
</TR>
</TABLE>
$ chkbox = $ _POST ['chk'];
$ txtbox = $ _POST ['txt'];
$ country = $ _POST ['country'];
$ passport = $ _POST ['passport'];
foreach($ txtbox为$ a =&gt; $ b)
echo“$ chkbox [$ a] - $ txtbox [$ a] - $ country [$ a] - $ passport [$ a]”;
工作正常,在屏幕上显示。然后我想以我的广泛形式集成它,我需要将其发送到我的邮件地址...请参阅下面的我的php示例(所有$ _POST还有其他的)。 'foreach'代码能够将上述动态行中的所有信息发送到我的邮件地址?为了让它可见,我还需要添加到我的$ message中?谢谢你的帮助。
$TripType = $_POST['TripType'];
$DepartureDay = $_POST['DepartureDay'];
$DepartureMonth = $_POST['DepartureMonth'];
$DepartureYear = $_POST['DepartureYear'];
$ReturnDay = $_POST['ReturnDay'];
$ReturnMonth = $_POST['ReturnMonth'];
$ReturnYear = $_POST['ReturnYear'];
$Adults = $_POST['Adults'];
$Children411 = $_POST['Children411'];
$Children03 = $_POST['Children03'];
foreach ($_POST['Check'] as $value) {$check_msg .= $value\n";}
$Comments = $_POST['Comments'];
$mail = $_POST['mail'];
$telephone = $_POST['telephone'];
$message = "Booking\n\nTripType: $TripType\n\nDepartureDay: $DepartureDay\nDepartureMonth: $DepartureMonth\nDepartureYear: $DepartureYear\n\nReturnDay: $ReturnDay\nReturnMonth: $ReturnMonth\nReturnYear: $ReturnYear\n\nAdults: $Adults\nChildren411: $Children411\nChildren03: $Children03\n $check_msg\nComments: $Comments\nmail: $mail\ntelephone: $telephone";
$xHeaders = "From: $mail\nX-Mailer: PHP/" . phpversion(); mail ("mymail@gmail.com", internet booking", $message, $xHeaders);
答案 0 :(得分:1)
这应该做你想要的。您的HTML不包含FORM或INPUT / submit,所以我猜他们在那里工作。
foreach($_POST['chk'] as $num => $value) {
$check_msg .= "$num = $value \n";
}
答案 1 :(得分:0)
尝试:
$message = '';
foreach ($_POST as $k => $v) {
$message .= $k.': '.$v.'\n';
}