I've downloaded SimpleCart (js) (http://simplecartjs.com/)
and I was able to make an e-mail checkout, but I want to cellect some
information from the buyer before checking out.
This is how far I've come:
The form in checkout.php:
<form action="sendjs.php" name="form" method="post">
<input placeholder="Namn" type="text" name="namn" value="Namn" id="namn" />
<input placeholder="Mobilnummer" type="text" name="telefon" value="Telefon" id="telefon" />
<a href="javascript:void(0);" onclick="javascript:Bestall();" class="simpleCart_checkout">
Beställ</a>
</form>
Javascript:
me.emailCheckout = function Bestall() {
itemsString = "";
for( var current in me.items ){
var item = me.items[current];
itemsString += item.quantity + " st\n" + item.name + "\n Pris: " + item.price + " kr/st \n\n";
}
namn += " ";
telefon += " ";
me.total += "" + " KR"
var form = document.createElement("form");
form.style.display = "none";
form.method = "POST";
form.action = "sendjs.php";
form.acceptCharset = "ISO-8859-1";
form.appendChild(me.createHiddenElement("jcitems", itemsString));
form.appendChild(me.createHiddenElement("jctotal", me.total));
form.appendChild(me.createHiddenElement("namn", namn));
form.appendChild(me.createHiddenElement("telefon", telefon));
document.body.appendChild(form);
form.submit();
document.form.submit();
document.body.removeChild(form);
}
me.customCheckout = function() {
return;
};
sendjs.php:
<?php
include 'simpleCart.js';
$to = 'jennifer.nilsson@hotellgruppen.se';
$subject = 'Beställning';
$jcitems = $_POST['jcitems'] .
" \n SUMMA: " . $_POST['jctotal'] .
" \n\n Namn: " . $_POST['namn'] .
" \n Telefon: " . $_POST['telefon'] .
" \n\n IP: " . $_SERVER['REMOTE_ADDR'] .
" \n Datum: " . date("Y-m-d") .
" \n Tid: " . date("H:i:s") ;
$headers = 'From: Bestallning@Mobil' . "\r\n" .
'Reply-To: Bestallning@Mobil' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $jcitems, $headers);
/*Clearing the cart info after succesfull order is made*/
setcookie ("simpleCart", "", time() - 3600);
Header('Location: tack.html');
?>
When I get the e-mail it displayed "[object HTMLInputElement]" where
the "namn"-value and "telefon"-value were supposed to be displayed, then
i googled around and found this:
<script type="text/javascript" charset="utf-8">
var namn = <?php echo json_encode($namn); ?>;
</script>
And I put that code in checkout.php but then it displays "null" instead.
Why doesn't it collect the information from the form?
Everything else works great, except the "namn" and "telefon" that I'm trying to collect from the form.
Thank you for your help!
EDIT:
Found the answer I think:
namn = document.form.namn.value;
telefon = document.form.telefon.value;
Changed this in the js and it seems to work! Why didn't I think of that before? ;)