私が現在取り組んでいるウェブサイトでは、顧客が製品を置くことができるリスト(カートのアイデア)を作った。それは次のようにセッションを行うためのコードは、GETメソッド+セッションで動作します:SESSION GET情報をPOST連絡先フォームとPOSTフィールドと共に送信
`<?php session_start();
require("dbconnect.php");
?>
<?php
if(!isset($_SESSION['cart'])) {
$cart = array();
$_SESSION['cart'] = $cart;
}
if(isset($_GET['action']) && $_GET['action']=="add"){
$id=intval($_GET['id']);
if(in_array($id, $_SESSION['cart'])){
if (($key = array_search($id, $_SESSION['cart'] !== false))){
unset($_SESSION['cart'][$key]);
}
}
else {
array_push($_SESSION['cart'],$id);
}
}
if(isset($_GET['action']) && $_GET['action']=="delete"){
$id = intval($_GET['id']);
if (in_array($id, $_SESSION['cart'])){
$key = array_search($id, $_SESSION['cart']);
unset($_SESSION['cart'][$key]);
}
}
?>
特別何も、私はすべてのユニークな製品のコードを入れて、アレイとのセッションではごく普通のカートリストにあるものを覚えておいてください。顧客が製品のリストを送ることができるページに行くとき、彼らはまた、彼らが望むそれぞれの製品の数を選択することができます。彼らは数字を記入しなければなりません。そして、完了したら、「計算(私の言語でberekenen)」ボタンをクリックすると、すべての製品の小計、付加価値税(VAT)と総価格が得られます。しかし、私は、顧客が自分の個人情報とリストに加えて電子メールで送信する金額を記入できるように、このようにしたい。私は自作のPHPフォームを自分で作成しましたが、今は固くなっています。私は注文リストのためにGETを使用しますが、私はいつも私のコンタクトフォームにPOSTフォームを使用します。どのように私はリストに加えて金額と連絡フォームフィールドの入力を送信する1つのボタンを作ることができますか?この瞬間、私はそれを次のように試しました(さらに多くの方法がありましたが、これまでにすべて失敗しました)。計算機能とオーダーリスト
<main>
<div class="main-center">
<div class="offerte-container">
<form action="" method="get" value="offertelijst">
<ul class="offerte-list">
<?php
$per_page = 9;
$args = array(
'post_type'=> 'wpcproduct',
'order' => 'ASC',
'orderby' => 'menu_order',
'posts_per_page' => $per_page
);
$products = new WP_Query($args);
?>
<?php
while($products->have_posts()): $products->the_post();
$id = get_the_ID();
$title = get_the_title();
$permalink = get_permalink();
$price = get_post_meta(get_the_id(),'wpc_product_price',true);
$product_id = get_post_meta(get_the_id(), 'product_ID', true);
if(in_array($id, $_SESSION['cart'])){
echo '<li class="wpc-product-item">';
echo '<a href="index.php?action=delete&id=' .$id. '">Verwijder </a>';
echo '<input alt="hoeveelheid" maxlengt="2" value="' .$_GET["amount$id"]. '" min="1" type="number" max="99" name="amount'.$id.'" size="3" required> </input>';
echo '<a href="'. $permalink .'"><div class="item-title"> ' .$title. ' </div></a>';
echo '<a href="'. $permalink .'"><div class="item-take"> <img width="25px" src="http://bgc-testomgeving.nl/sem/wp-content/themes/sem/images/pijltje.png" /> </div></a>';
echo '<a href="'. $permalink .'"><div class="item-nr"> '.$product_id. '</div></a>';
if((isset($_GET["amount$id"]) && $_GET["amount$id"] == 1) || $_GET["amount$id"] == ""){
if (is_numeric($price) && (floor($price) == $price)) {
echo '<div class="item-price"> €' .number_format ($price , 0 , "," , "."). ',- </div>';
}
else {
echo '<div class="item-price"> €' .$price. '</div>';
}
echo '</li>';
}
else if(isset($_GET["amount$id"]) && floatval($_GET["amount$id"]) > 1){
changeFormat($price);
$priceTotal = number_format($price * floatval($_GET["amount$id"]), 2);
if (is_numeric($priceTotal) && (floor($priceTotal) == $priceTotal)) {
echo '<div class="item-price"> €' .$priceTotal . ',- </div>';
}
else {
echo '<div class="item-price"> €' .$priceTotal . '</div>';
}
echo '</li>';
}}
endwhile;
?>
</ul>
<input type="submit" value="Bereken"> </input>
</form>
<div class="totalprice">
<?php
(float)$total = 0;
while($products->have_posts()): $products->the_post(); {
$id = get_the_ID();
$title = get_the_title();
$permalink = get_permalink();
$price = get_post_meta(get_the_id(),'wpc_product_price',true);
$product_id = get_post_meta(get_the_id(), 'product_ID', true);
if(in_array($id, $_SESSION['cart'])){
if (is_numeric($price) && (floor($price) == $price)) {
$price = number_format($price, 2);
}
else {
$price = str_replace(',', '.', $price);
}
$total += (floatval($price) * floatval($_GET["amount$id"]));
}}
endwhile;
(String)$total;
number_format($total, 2);
$totalDecimal = str_replace('.', ',', $total);
echo 'Subtotaal: €' .$totalDecimal. '<br />';
echo 'BTW: €' . str_replace('.',',', number_format($total * 0.21,2)). '<br />';
echo 'Totaal: €' . str_replace('.',',', number_format($total * 1.21,2));
function changeFormat($var) {
if(is_numeric($var) && (floor($var) == $var)){
return number_format($var, 0) + ',-';
}
else {
if (is_numeric($var)) {
return number_format($var, 2, ',', '.');
}
else if (is_string ($var)){
return str_replace(',', '.', $var);
}
else {
echo "What the hell is dit voor een formaat?";
}
}}
?>
</div>
</div>
</div>
</main>
はすべて正常に動作していると私はのContactFormとして、標準のPOSTフォームを作ることができるが、私はこれを成し遂げるために管理することはできません。私は、製品ごとに与えられた金額と連絡フォームに記入された金額とリストを送信するために、「送信」ボタンを押してください。
このプロジェクトのためのURLは次のとおりです。http://www.bgc-testomgeving.nl/sem/offertelijst/ページの下側にhttp://www.bgc-testomgeving.nl/sem は、お問い合わせフォームでなければなりませんが、私はこれを構築しようとするたびに私は私の完璧な順序リストを解体します。