php og javascript
HejJeg har denne kode som skal arbejde sammen med en php mail form...
Det virker sådan set også næsten... problemet er når der er flere produkter så er det kun det første produkt der bliver sendt med mail formen.
De felter jeg vil have sendt vidre er dem her omkring document.writeln('<INPUT TYPE="hidden" NAME="Artikel" i koden neden for...
filen med javascriptet i
========================
<SCRIPT language=JavaScript>
// alterError - fixes a rounding bug in Netscape 2
function alterError(value) {
if (value<=0.99) {
newPounds = '0';
} else {
newPounds = parseInt(value);
}
newPence = parseInt((value+.0008 - newPounds)* 100);
if (eval(newPence) <= 9) newPence='0'+newPence;
newString = newPounds + '.' + newPence;
return (newString);
}
// showItems () - creates a table of items in the basket and
// creates the start of a form which sets information for
// basket items.
function showItems() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('<FORM NAME="BUY" action="mail.php" METHOD=POST>');
document.writeln('<input type="hidden" name="recipient" value="EMAIL@EMAIL:DK">');
document.writeln('<input type="hidden" name="subject" value="online bestilling">');
document.writeln('<input type="hidden" name="redirect" value="DOMÆNE:DK">');
document.writeln('<TABLE width="460" BORDER=0 CELLPADDING=1 CELLSPACING=1 background="filer/bagg2.gif">');
document.writeln('<TR><TD width="240"><b><font size="2" FACE="Verdana" COLOR="#ffffff"">Artikel</font></b></TD><TD width="70"><b><font size="2" FACE="Verdana" COLOR="#ffffff""> Antal</font></b></TD><TD width="70"><b><font size="2" FACE="Verdana" COLOR="#ffffff""> kr/stk</font></b></TD><td width="70" align="right"><b><font size="2" FACE="Verdana" COLOR="#ffffff"">kr total</font></b></td></TR>');
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
totprice = totprice + itemtotal;
itemlist=itemlist+1;
document.write('<tr><td><FONT SIZE="2" FACE="verdana">'+theitem+'</td>');
document.writeln('<td align=left><FONT SIZE="2" FACE="verdana"> '+thequantity+'</td><td align=left><FONT SIZE="2" FACE="verdana">'+theprice+'</td><td align=right><FONT SIZE="2" FACE="verdana"> '+alterError(itemtotal)+'</td></tr>');
document.writeln('<INPUT TYPE="hidden" NAME="Artikel" NAME="Artikel '+itemlist+'" VALUE="'+theitem+'" SIZE="40">');
document.writeln('<INPUT TYPE="hidden" NAME="Antal" NAME="Antal '+itemlist+'" VALUE="'+thequantity+'" SIZE="40">');
document.writeln('<INPUT TYPE="hidden" NAME="Pris/stk" NAME="Pris/stk '+itemlist+'" VALUE="'+theprice+'" SIZE="40">');
document.writeln('<INPUT TYPE="hidden" NAME="Total" NAME="Total'+itemlist+'" VALUE="'+alterError(itemtotal)+'" SIZE="40">');
} else if (fulllist.substring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substring(itemstart, i);
if (thisitem==2) theprice = fulllist.substring(itemstart, i);
thisitem++;
itemstart=i+1;
}
}
document.writeln('<tr><td background="filer/bagg3.gif" colspan=3><b><FONT SIZE="2" FACE="verdana" COLOR="Black">Kr. total excl. fragt*.</FONT></b></td><td align=right background="filer/bagg3.gif"><FONT SIZE="2" FACE="verdana" COLOR="Black"><b>'+alterError(totprice)+'</b></td></tr>');
document.writeln('<INPUT TYPE="hidden" NAME="Varer Total" VALUE="'+alterError(totprice)+'" SIZE="40">');
document.writeln('</TABLE>');
}
</SCRIPT>
<p align="left"><script LANGUAGE="JavaScript">
showItems();
</script> </p>
mail.php
========
<?PHP
$besked = "$Artikel,$Antal,$Pris/stk
$Artikel1,$Antal1,$Pris/stk1";
mail("hej@hej.dk", "My Subject", "$besked");
?>