En löytänyt Jcart sivuston (http://conceptlogic.com/jcart/) foorumilta ongelmaani ratkaisua.
Haluaisin saada checkoutissa ennen tilaamista saada lomakkeen johon asiakas voi syöttää tietonsa.
Tässä checkout sivun koodi:
<?php // jCart v1.3 // http://conceptlogic.com/jcart/ // This file demonstrates a basic checkout page // If your page calls session_start() be sure to include jcart.php first include_once('jcart/jcart.php'); session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Unensieppaaja</title> <link rel="stylesheet" type="text/css" media="screen, projection" href="style.css" /> <link rel="stylesheet" type="text/css" media="screen, projection" href="jcart/css/jcart.css" /> </head> <body> <div id="wrapper"> <h2>Ostoskori</h2> <div id="sidebar"> </div> <div id="content"> <div id="jcart"><?php $jcart->display_cart();?></div> <p><a href="index.php">Jatka ostoksia!</a></p> <form method="post" action="" class="jcart"> <fieldset> <ul> <li>Nimi:</li> <input type="text" name="my-item-nimi" value="" /> <li>Email:</li> <input type="text" name="my-item-email" value="" /> <li>Katuosoite:</li> <input type="text" name="my-item-katu" value="" /> <li>Postinumero:</li> <input type="text" name="my-item-pnumero" value="" /> <li>Postitoimipaikka:</li> <input type="text" name="my-item-toimip" value="" /> </ul> </fieldset> </form> <?php //echo '<pre>'; //var_dump($_SESSION['jcart']); //echo '</pre>'; ?> </div> <div class="clear"></div> </div> <script type="text/javascript" src="jcart/js/jquery-1.4.4.min.js"></script> <script type="text/javascript" src="jcart/js/jcart.min.js"></script> </body> </html>
Tässä sitten gateway sivun koodi joka käsittelee checkout sivun tilaamisen jälkeen:
<?php // JCART v1.1 // http://conceptlogic.com/jcart/ // THIS FILE IS CALLED WHEN ANY BUTTON ON THE CHECKOUT PAGE (PAYPAL CHECKOUT, UPDATE, OR EMPTY) IS CLICKED // WE CAN ONLY DEFINE ONE FORM ACTION, SO THIS FILE ALLOWS US TO FORK THE FORM SUBMISSION DEPENDING ON WHICH BUTTON WAS CLICKED // ALSO ALLOWS US TO VERIFY PRICES BEFORE SUBMITTING TO PAYPAL // INCLUDE JCART BEFORE SESSION START include_once 'jcart.php'; // START SESSION session_start(); // INITIALIZE JCART AFTER SESSION START $cart =& $_SESSION['jcart']; if(!is_object($cart)) $cart = new jcart(); // WHEN JAVASCRIPT IS DISABLED THE UPDATE AND EMPTY BUTTONS ARE DISPLAYED // RE-DISPLAY THE CART IF THE VISITOR CLICKS EITHER BUTTON if ($_POST['jcart_update_cart'] || $_POST['jcart_empty']) { // UPDATE THE CART if ($_POST['jcart_update_cart']) { $cart_updated = $cart->update_cart(); if ($cart_updated !== true) { $_SESSION['quantity_error'] = true; } } // EMPTY THE CART if ($_POST['jcart_empty']) { $cart->empty_cart(); } // REDIRECT BACK TO THE CHECKOUT PAGE header('Location: ' . $_POST['jcart_checkout_page']); exit; } // THE VISITOR HAS CLICKED THE PAYPAL CHECKOUT BUTTON else { /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// /* A malicious visitor may try to change item prices before checking out, either via javascript or by posting from an external script. Here you can add PHP code that validates the submitted prices against your database or validates against hard-coded prices. The cart data has already been sanitized and is available thru the $cart->get_contents() function. For example: */ /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// foreach ($cart->get_contents() as $item) { $item_id = $item['id']; $item_name = $item['name']; $item_price = $item['price']; $item_qty = $item['qty']; $item_nimi = $item['nimi']; $item_katu = $item['katu']; $item_pnummero = $item['pnumero']; $item_toimip = $item['toimip']; } $valid_prices = true; /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // IF THE SUBMITTED PRICES ARE NOT VALID if ($valid_prices !== true) { // KILL THE SCRIPT die($jcart['text']['checkout_error']); } // PRICE VALIDATION IS COMPLETE // SEND CART CONTENTS TO PAYPAL USING THEIR UPLOAD METHOD, FOR DETAILS SEE http://tinyurl.com/djoyoa else if ($valid_prices === true) { // Here we will construct a new email message to be sent to the merchant // upon completion of the checkout process. The example message below is // intentionally simplistic, and meant to be modified to your preferences. $message = "Uusi tilaus:\n\n"; foreach ($cart->get_contents() as $item) { $message .= 'Tuote: ' . $item['name']; $message .= "\nHinta: " . $item['price']; $message .= "\nMäärä: " . $item['qty']; $message .= "\n\n"; $message .= "Tilaaja: " . $item['nimi']; $message .= "\nOsoite: " . $item['katu']; $message .= "\nPostinumero: " . $item['pnumero']; $message .= "\nPostitoimipaikka: " . $item['toimip']; $message .= "\nEmail: " . $item['email']; } // The following line uses PHP's built-in mail() function to send the email. // Most servers/hosts support this method by default, while others may // require it to be enabled, or configured differently. For more information // about the mail() function see: https://www.php.net/manual/en/function.mail.php // // The function call returns a boolean value indicating whether the mail was // successfully accepted by the server's mail daemon for delivery. $mailSent = mail('tilaus@saqe-art.com', 'Unensieppaaja -tilaus', $message); // EMPTY THE CART $cart->empty_cart(); // Done! You can either output a purchase "reciept" here, or redirect the // user to another page. echo "<h1>Tilauksesi on lahetetty!</h1>"; } } ?>
Saan sähköpostiin kyllä ostoskorin sisällön ja otsikot asiakastietoihin, mutta lomakkeen tiedot eivät välity sähköpostiin. Olen laittanut myös tiedostoihin config.php ja jcart.php sivuun myös item tiedot asiakastiedoista.
Kiitos etukäteen jälleen avusta!
Mod. korjasi oikeat kooditagit.
Missä kohdassa lomakkeen tiedot käsitellään? Se ei selviä tuosta koodista. Tarkista ainakin, että todella käsittelet lomakkeen tiedot ja lisäät ne sopivassa kohtaa viestiin, joka lähtee sähköpostiisi.
Aihe on jo aika vanha, joten et voi enää vastata siihen.