Note that there are some explanatory texts on larger screens.

plurals
  1. POPass javascript into a .txt file with PHP
    primarykey
    data
    text
    <p>Ok so far I have had some help from you guys and this is the last thing that I have spent way too much time on.</p> <p>I am using nopCart for an online store for uni. We aren't required to do the back end stuff but I have been saving the customer details to a text file. Inititally I was able to get everything sent via email but since going through PHP I don't know how to get the order details. The customer information is entered into text boxes and then saved to the text file via PHP.</p> <p>My checkout code </p> <pre><code> &lt;form action="process.php" method ="post"&gt; &lt;script type="text/javascript"&gt; CheckoutCart(); &lt;/script&gt; &lt;br /&gt;&lt;br /&gt; First Name: &lt;input type="text" name="first" /&gt;&lt;br /&gt; Last Name: &lt;input type="text" name="last" /&gt;&lt;br /&gt; Street Address: &lt;input type="text" name="address" /&gt;&lt;br /&gt; Suburb: &lt;input type="text" name="suburb" /&gt;&lt;br /&gt; State: &lt;input type="text" name="state" /&gt;&lt;br /&gt; Postcode: &lt;input type="text" name="postcode" /&gt;&lt;br /&gt; Country: &lt;input type="text" name="country" /&gt;&lt;br /&gt; Phone Number: &lt;input type="text" name="phone" /&gt;&lt;br /&gt; Email: &lt;input type="text" name="email" /&gt;&lt;br /&gt; shop: &lt;input type="text" name="shop" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; Other form data can go here when you create your prototype cart ... &lt;br /&gt;&lt;br /&gt; &lt;input type="submit" name="submitButton" value=" Submit Order " /&gt; &lt;/form&gt; </code></pre> <p>Input shop is not currently being used, where I have trying to get the order information into</p> <p>My process.php code</p> <pre><code>&lt;?php // We will put the data into a file in the current directory called "data.txt" // But first of all, we need to check if the user actually pushed submit if (isset($_POST['submitButton'])) { // The user clicked submit // Put the contents of the text into the file file_put_contents('./data.txt', $_POST['shop'] . " " .$_POST['first'] . " " . $_POST['last'] . "\n" . $_POST['address'] . "\n" . $_POST['suburb'] . " " . $_POST['state'] . " " . $_POST['postcode'] . "\n" . $_POST['country'] . "\n" . "\n", FILE_APPEND); // ./data.txt: the text file in which the data will be stored // $_POST['myInputName']: What the user put in the form field named "myInputName" // FILE_APPEND: This tells the function to append to the file and not to overwrite it. } ?&gt; </code></pre> <p>In an earlier version using this code in the checkout.html. This would email me everything i needed</p> <pre><code>&lt;!-- Checkout Begin--&gt; The items listed below are currently in your shopping cart: &lt;form action="mailto:xxxxxxx@example.com" method ="post"&gt; &lt;script type="text/javascript"&gt; CheckoutCart(); &lt;/script&gt; &lt;br /&gt;&lt;br /&gt; Name: &lt;input type="text" name="b_first" /&gt; &lt;input type="text" name="b_last" /&gt;&lt;br /&gt; Email: &lt;input type="text" name="b_email" /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; Other form data can go here when you create your prototype cart ... &lt;br /&gt;&lt;br /&gt; &lt;input type="submit" value=" Submit Order " /&gt; &lt;/form&gt; &lt;!-- Checkout End --&gt; </code></pre> <p>On clicking the send button I would get this text opening in a new email</p> <p>ID_1=ID+000&amp;QUANTITY_1=1&amp;PRICE_1=28.99&amp;NAME_1=Cat+Scratcher&amp;SHIPPING_1=4.99&amp;ADDTLINFO_1=&amp;SUBTOTAL=%2428.99&amp;SHIPPING=%244.99&amp;TAX=%240.00&amp;TOTAL=%2433.98&amp;b_first=Jonny&amp;b_last=Smith&amp;b_email=a%40a.com</p> <p>I would like to be able to get this string here into the .txt file with the customer details. Is there an easy way to get this information from CheckoutCart() and save it in a text box so I can then add it to my process.php and get it into the text file?</p> <p>So far I have just been using trial and error and I'm really not sure what to do next</p> <p>Here is the checkoutCart function from nopcart.js</p> <pre><code>//---------------------------------------------------------------------|| // FUNCTION: CheckoutCart || // PARAMETERS: Null || // RETURNS: Product Table Written to Document || // PURPOSE: Draws current cart product table on HTML page for || // checkout. || //---------------------------------------------------------------------|| function CheckoutCart( ) { var iNumberOrdered = 0; //Number of products ordered var fTotal = 0; //Total cost of order var fTax = 0; //Tax amount var fShipping = 0; //Shipping amount var strTotal = ""; //Total cost formatted as money var strTax = ""; //Total tax formatted as money var strShipping = ""; //Total shipping formatted as money var strOutput = ""; //String to be written to page var bDisplay = true; //Whether to write string to the page (here for programmers) var strPP = ""; //Payment Processor Description Field iNumberOrdered = GetCookie("NumberOrdered"); if ( iNumberOrdered == null ) iNumberOrdered = 0; if ( TaxByRegion ) { QueryString_Parse(); fTax = parseFloat( QueryString( OutputOrderTax ) ); strTax = moneyFormat(fTax); } if ( bDisplay ) strOutput = "&lt;TABLE CLASS=\"nopcart\"&gt;&lt;TR&gt;" + "&lt;TD CLASS=\"nopheader\"&gt;&lt;B&gt;"+strILabel+"&lt;/B&gt;&lt;/TD&gt;" + "&lt;TD CLASS=\"nopheader\"&gt;&lt;B&gt;"+strDLabel+"&lt;/B&gt;&lt;/TD&gt;" + "&lt;TD CLASS=\"nopheader\"&gt;&lt;B&gt;"+strQLabel+"&lt;/B&gt;&lt;/TD&gt;" + "&lt;TD CLASS=\"nopheader\"&gt;&lt;B&gt;"+strPLabel+"&lt;/B&gt;&lt;/TD&gt;" + (DisplayShippingColumn?"&lt;TD CLASS=\"nopheader\"&gt;&lt;B&gt;"+strSLabel+"&lt;/B&gt;&lt;/TD&gt;":"") + "&lt;/TR&gt;"; for ( i = 1; i &lt;= iNumberOrdered; i++ ) { NewOrder = "Order." + i; database = ""; database = GetCookie(NewOrder); Token0 = database.indexOf("|", 0); Token1 = database.indexOf("|", Token0+1); Token2 = database.indexOf("|", Token1+1); Token3 = database.indexOf("|", Token2+1); Token4 = database.indexOf("|", Token3+1); fields = new Array; fields[0] = database.substring( 0, Token0 ); // Product ID fields[1] = database.substring( Token0+1, Token1 ); // Quantity fields[2] = database.substring( Token1+1, Token2 ); // Price fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description fields[4] = database.substring( Token3+1, Token4 ); // Shipping Cost fields[5] = database.substring( Token4+1, database.length ); //Additional Information fTotal += (parseInt(fields[1]) * parseFloat(fields[2]) ); fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) ); if ( !TaxByRegion ) fTax = (fTotal * TaxRate); strTotal = moneyFormat(fTotal); if ( !TaxByRegion ) strTax = moneyFormat(fTax); strShipping = moneyFormat(fShipping); if ( bDisplay ) { strOutput += "&lt;TR&gt;&lt;TD CLASS=\"nopentry\"&gt;" + fields[0] + "&lt;/TD&gt;"; if ( fields[5] == "" ) strOutput += "&lt;TD CLASS=\"nopentry\"&gt;" + fields[3] + "&lt;/TD&gt;"; else strOutput += "&lt;TD CLASS=\"nopentry\"&gt;" + fields[3] + " - &lt;I&gt;"+ fields[5] + "&lt;/I&gt;&lt;/TD&gt;"; strOutput += "&lt;TD CLASS=\"nopentry\"&gt;" + fields[1] + "&lt;/TD&gt;"; strOutput += "&lt;TD CLASS=\"nopentry\"&gt;"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea&lt;/TD&gt;"; if ( DisplayShippingColumn ) { if ( parseFloat(fields[4]) &gt; 0 ) strOutput += "&lt;TD CLASS=\"nopentry\"&gt;"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea&lt;/TD&gt;"; else strOutput += "&lt;TD CLASS=\"nopentry\"&gt;N/A&lt;/TD&gt;"; } strOutput += "&lt;/TR&gt;"; } if ( AppendItemNumToOutput ) { strFooter = i; } else { strFooter = ""; } if ( PaymentProcessor != '' ) { //Process description field for payment processors instead of hidden values. //Format Description of product as: // ID, Name, Qty X strPP += fields[0] + ", " + fields[3]; if ( fields[5] != "" ) strPP += " - " + fields[5]; strPP += ", Qty. " + fields[1] + "\n"; } else { strOutput += "&lt;input type=hidden name=\"" + OutputItemId + strFooter + "\" value=\"" + fields[0] + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"" + OutputItemQuantity + strFooter + "\" value=\"" + fields[1] + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"" + OutputItemPrice + strFooter + "\" value=\"" + fields[2] + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"" + OutputItemName + strFooter + "\" value=\"" + fields[3] + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"" + OutputItemShipping + strFooter + "\" value=\"" + fields[4] + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\"&gt;"; } } if ( bDisplay ) { strOutput += "&lt;TR&gt;&lt;TD CLASS=\"noptotal\" COLSPAN=3&gt;&lt;B&gt;"+strSUB+"&lt;/B&gt;&lt;/TD&gt;"; strOutput += "&lt;TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT&gt;&lt;B&gt;" + MonetarySymbol + strTotal + "&lt;/B&gt;&lt;/TD&gt;"; strOutput += "&lt;/TR&gt;"; if ( DisplayShippingRow ) { strOutput += "&lt;TR&gt;&lt;TD CLASS=\"noptotal\" COLSPAN=3&gt;&lt;B&gt;"+strSHIP+"&lt;/B&gt;&lt;/TD&gt;"; strOutput += "&lt;TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT&gt;&lt;B&gt;" + MonetarySymbol + strShipping + "&lt;/B&gt;&lt;/TD&gt;"; strOutput += "&lt;/TR&gt;"; } if ( DisplayTaxRow || TaxByRegion ) { strOutput += "&lt;TR&gt;&lt;TD CLASS=\"noptotal\" COLSPAN=3&gt;&lt;B&gt;"+strTAX+"&lt;/B&gt;&lt;/TD&gt;"; strOutput += "&lt;TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT&gt;&lt;B&gt;" + MonetarySymbol + strTax + "&lt;/B&gt;&lt;/TD&gt;"; strOutput += "&lt;/TR&gt;"; } strOutput += "&lt;TR&gt;&lt;TD CLASS=\"noptotal\" COLSPAN=3&gt;&lt;B&gt;"+strTOT+"&lt;/B&gt;&lt;/TD&gt;"; strOutput += "&lt;TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT&gt;&lt;B&gt;" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "&lt;/B&gt;&lt;/TD&gt;"; strOutput += "&lt;/TR&gt;"; strOutput += "&lt;/TABLE&gt;"; if ( PaymentProcessor == 'an') { //Process this for Authorize.net WebConnect strOutput += "&lt;input type=hidden name=\"x_Version\" value=\"3.0\"&gt;"; strOutput += "&lt;input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\"&gt;"; strOutput += "&lt;input type=hidden name=\"x_Description\" value=\""+ strPP + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"x_Amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\"&gt;"; } else if ( PaymentProcessor == 'wp') { //Process this for WorldPay strOutput += "&lt;input type=hidden name=\"desc\" value=\""+ strPP + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\"&gt;"; } else if ( PaymentProcessor == 'lp') { //Process this for LinkPoint strOutput += "&lt;input type=hidden name=\"mode\" value=\"fullpay\"&gt;"; strOutput += "&lt;input type=hidden name=\"chargetotal\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"tax\" value=\""+ MonetarySymbol + strTax + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"subtotal\" value=\""+ MonetarySymbol + strTotal + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"shipping\" value=\""+ MonetarySymbol + strShipping + "\"&gt;"; strOutput += "&lt;input type=hidden name=\"desc\" value=\""+ strPP + "\"&gt;"; } else { strOutput += "&lt;input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\"&gt;"; strOutput += "&lt;input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\"&gt;"; strOutput += "&lt;input type=hidden name=\""+OutputOrderTax+"\" value=\""+ MonetarySymbol + strTax + "\"&gt;"; strOutput += "&lt;input type=hidden name=\""+OutputOrderTotal+"\" value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\"&gt;"; } } document.write(strOutput); document.close(); } //=====================================================================|| // END NOP Design SmartPost Shopping Cart || //=====================================================================|| </code></pre> <p>I know it's a lot of text and code but I don't think it will be too hard to find a solution, it is only the first in depth HTML subject in my course and I am hoping to get this working.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload