0
カートアイテムは電子メールに送信されますが、フォームからの入力は送信されません。simpleCart.jsは、PHPスクリプトを使用してフォーム入力とカートアイテムをEMAILに送信します。 - フォーム入力を送信できません
は、ここに私のコードです:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Atelier K - Trimite Comanda</title>
<link rel="icon" href="images/iconAK.ico"/>
<!-- Bootstrap -->
<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/simpleCart.js"></script>
<script src="js/simplecart.min.js"></script>
<script src="js/qunit.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script>
simpleCart({
cartColumns: [
//{ attr: "image", label: false, view: "Imagine"},
{ attr: "name" , label: "Produs" },
{ attr: "quantity", label: "CAntitate", view: "input"},
{ view:'remove', text: "X", label: "Sterge"},
//Price of item
//{ attr: "price", label: "Pret", view: "currency"},
//Subtotal of that row (quantity of that item * the price)
{ attr: "total" , label: "Sub Toalt", view: "currency" }
],
cartStyle: "table" ,
checkout: {
type: "SendForm" ,
url: "/contact/Comandascript.php" ,
method: "POST" ,
success: "/contact/Comanda_trimisa.php" ,
cancel: "/contact/Comanda_netrimisa.php" ,
extra_data: {
Prenume : document.getElementById("firstname").value,
Nume : document.getElementById("lastname").value,
Address : document.getElementById("address").value,
email : document.getElementById("email").value,
Telefon : document.getElementById("phone").value,
Mesaj : document.getElementById("comments").value,
}
}
});
simpleCart.bind('beforeCheckout' , function(data){
data.first_name = document.getElementById("firstname").value;
data.last_name = document.getElementById("lastname").value;
data.address = document.getElementById("address").value;
data.email = document.getElementById("email").value;
data.phone = document.getElementById("phone").value;
data.comments = document.getElementById("comments").value;
});
</script>
</head>
<body>
<section>
<div class="container">
<!-- Form -->
<form name="myform" id="myForm" method="POST" action="/contact/Comandascript.php">
<fieldset>
<h4 style="color: #4682B4"> Persoana de contact</h4>
<p> </p>
<table>
<tr>
<th> <p> <label for="firstname">Prenume: </label> </th>
<th><input type="text" name="firstname" placeholder="" title="Introduceti prenumele" class="required" id="firstname" size="50px" onblur='isEmpty(this.value)' ><font size="1" color="red"> <span id="msg"></span></font></p></th>
</tr>
<tr>
<th> <p> <label for="lastname">Nume: </label> </th>
<th><input type="text" name="lastname" placeholder="" title="Introduceti numele de familie" class="required" id="lastname" size="50px" onblur='isEmpty1(this.value)' > <font size="1" color="red"><span id="msg1"></span></font></p></th>
</tr>
</table>
<hr>
<h4 style="color: #4682B4">Date de Livrare</h4>
<p> </p>
<table>
<tr>
<th> <p> <label for="address">Adresa de livrare: </label> </th>
<th> <input type="text" name="address" placeholder="" title="Introduceti adresa de livrare" class="required" id="address" size="50px" onblur='isEmpty2(this.value)' ><font size="1" color="red"><span id="msg2"></span></font></p> </th>
</tr>
<tr>
<th> <p> <label for="email">Email: </label> </th>
<th> <input type="email" name="email" placeholder="" title="Introduceti o adresa de email corecta" class="required email" id="email" size="50px" onblur='isEmpty3(this.value)'><font size="1" color="red"><span id="msg3"></span></font></p> </th>
</tr>
<tr>
<th> <p> <label for="phone">Telefon: </label> </th>
<th> <input type="tel" name="phone" placeholder="" id="phone" size="50px" title="Introduceti numarul dvs. de telefon." onblur='isEmpty4(this.value)' onkeypress='return isNumberKey(event)'><font size="1" color="red"><span id="msg4"></span></font></p> </th>
</tr>
</table>
<hr>
<h4 style="color: #4682B4"> Informatii Suplimentare</h4>
<p> </p>
<table>
<tr>
<th> <p> <label for="message">Mesaj: </label> </th>
<th> <input type="text" title="Completati aici daca doriti sa ne transmiteti info extra" name="message" placeholder="Completati aici daca doriti sa ne transmiteti info. extra." id="message" size="75px"></p></th>
</tr>
</table>
<hr>
</fieldset>
<a href="javascript:;" id="submit" name="submit" value="submit" class="simpleCart_checkout" ><span class="checkout_btn"> Trimite comanda</span></a>
</form>
</div> <!-- /end #contact-form -->
</div>
</section>
<hr>
</body>
</html>
PHPコード
<?php
$content = $_POST; /* receiving SimpleCart order array */
$body = ''; /* declaring the email body */
$firstname = ''; /* extra field variable */
$lastname = ''; /* extra field variable */
$email = ''; /* extra field variable */
$address = '';
$phone = ''; /* extra field variable */
$comments = ''; /* extra field variable */
$body .= '=================================='."\n";
$body .= "Prenume: ".$content[$firstname]."\n"; /* using extra field variable */
$body .= "Nume de familie: ".$content[$lastname]."\n"; /* using extra field variable */
$body .= "Adresa: ".$content[$address]."\n"; /* using extra field variable */
$body .= "Email: ".$content[$email]."\n"; /* using extra field variable */
$body .= "Numar de telefon: ".$content[$phone]."\n"; /* using extra field variable */
$body .= 'Has placed the following order:'."\n";
$body .= "\n";
$body .= '=================================='."\n";
/* starting the loop to get all orders from the stored array */
for($i=1; $i < $content['itemCount'] + 1; $i++) {
$name = 'item_name_'.$i; /* product name variable */
$quantity = 'item_quantity_'.$i; /* product quantity variable */
$price = 'item_price_'.$i; /* product price variable */
$total = $content[$quantity]*$content[$price]; /* product total price variable (price*quantity) */
$grandTotal += $total; /* accumulating the total of all items */
$body .= 'Comanda#'.$i.': '.$content[$name]."\n".'Cantitate '.$content[$quantity].' --- Pret per bucata $'.number_format($content[$price], 2, '.', '')."\n".'Sub-total $'.number_format($total, 2, '.', '')."\n"; /* creating a semantic format for each ordered product */
$body .= '=================================='."\n";
}
/* ending the loop to get all orders from the stored array */
$body .= 'Total: $'.number_format($grandTotal, 2, '.', '')."\n"; /* total amount of the order */
$body .= '=================================='."\n";
$body .= "\n";
$body .= "Mesaj(optional): ".$content[$comments]."\n"; /* using extra field variable */
$headers = "Content-Type: text/plain; charset=iso-8859-1\n";
$headers .= "From: $firstname $lastname <$email>\n";
$recipient = "[email protected]";
$subject = "Comanda noua pentru K";
mail($recipient, $subject, $body, $headers); /* building the mail() function */
header("location: /contact/Comanda_trimisa.php"); /* declaring the page to redirect if the mail is sent successfully */
?>
私はsimpleCart.jsとSendFormについて見られる異なる例を試みたが、それだけでは動作しませドス。私がclass = "simpleCart_checkout"を送信リンクから取り出した場合、私はカートアイテムを取得しません。入力タグtype = "submit"をクラスなしで使用すると、フォーム入力が取得されます。 同じPHPスクリプトを使用してメールを送信するにはどうすればよいですか?私は上記の投稿HTMLコードから
この部分を削除します:
解決したら、回答を回答としてマークする必要があります –