将JavaScript传递到使用PHP的.txt文件中 [英] Pass javascript into a .txt file with PHP

查看:80
本文介绍了将JavaScript传递到使用PHP的.txt文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经从你们那里得到了一些帮助,这是我花费太多时间在最后一件事。



我正在使用nopCart for一个单一的在线商店。我们不需要做后端的工作,但我一直在保存客户的详细信息到一个文本文件。起初,我能够通过电子邮件发送所有内容,但自从通过PHP后,我不知道如何获取订单详细信息。客户信息输入到文本框中,然后通过PHP保存到文本文件中。



我的结帐代码

 < form action =process.phpmethod =post> 
< script type =text / javascript>
CheckoutCart();
< / script>
< br />< br />
名字:< input type =textname =first/>< br />
姓氏:< input type =textname =last/>< br />
街道地址:< input type =textname =address/>< br />
郊区:< input type =textname =suburb/>< br />
状态:< input type =textname =state/>< br />
邮政编码:< input type =textname =postcode/>< br />
国家:< input type =textname =country/>< br />
电话号码:< input type =textname =phone/>< br />
电子邮件:< input type =textname =email/>< br />

shop:< input type =textname =shop/>< br />
< br />< br />
其他表单数据可以在您创建原型购物车时进入此处...
< br />< br />

< input type =submitname =submitButtonvalue =Submit Order/>
< / form>

输入商店当前未被使用,我试图将订单信息输入



我的process.php代码

 <?php 
/ /我们会将数据放到当前目录下的一个文件中,名为data.txt
//但首先,我们需要检查用户是否真的推送了
if(isset($ _ POST ['submitButton'])){
//用户点击提交
//将文本内容放入文件
file_put_contents('./ data.txt',$ _POST [ ''。'。'。'。。$ _ POST ['first']。。$ _POST ['last']。\\\
。$ _POST ['address']。\\\
。$ _POST [ ''。'。'。。$ _POST ['state']。。$ _POST ['postcode']。\\\
。$ _POST ['country']。\\\
。\ n,FILE_APPEND);
// ./data.txt:存储数据的文本文件
// $ _POST ['myInputName']:用户放入名为myInputName的表单字段
// FILE_APPEND:它告诉函数追加到文件而不覆盖它。
}
?>

在checkout.html中使用此代码的早期版本中。这可以给我发送我需要的所有东西

 <! -  Checkout Begin  - > 
下面列出的商品目前在您的购物车中:

< form action =mailto:xxxxxxx@example.commethod =post>
< script type =text / javascript>
CheckoutCart();
< / script>
< br />< br />
名称:< input type =textname =b_first/>
< input type =textname =b_last/>< br />
电子邮件地址:< input type =textname =b_email/>< br />
< br />< br />
其他表单数据可以在您创建原型购物车时进入此处...
< br />< br />

< input type =submitvalue =Submit Order/>
< / form>
<! - 结帐结束 - >

点击发送按钮后,我将在新邮件中打开此文本



ID_1 = ID + 000& QUANTITY_1 = 1& PRICE_1 = 28.99& NAME_1 = Cat + Scratcher& SHIPPING_1 = 4.99& ADDTLINFO_1 =& SUBTOTAL =%2428.99& SHIPPING =%244.99& amp ; TAX =%240.00& TOTAL =%2433.98& b_first = Jonny& b_last = Smith& b_email = a%40a.com

我希望能够将此字符串与客户详细信息一起放入.txt文件中。有没有一种简单的方法可以从CheckoutCart()中获取这些信息并将其保存在文本框中,然后我可以将它添加到我的process.php并将其放入文本文件中?



到目前为止,我刚刚使用试验和错误,我真的不知道下一步该做什么。



这是nopcart.js中的checkoutCart函数

  // ------------------------- -------------------------------------------- || 
//功能:CheckoutCart ||
//参数:无||
//返回:产品表写入文档||
//目的:在HTML页面上为||绘制当前购物车产品表
//结帐。 ||
// -------------------------------------------- ------------------------- ||
函数CheckoutCart(){
var iNumberOrdered = 0; //订购的产品数量
var fTotal = 0; //订单总成本
var fTax = 0; //税额
var fShipping = 0; //运费金额
var strTotal =; //总费用格式设置为
var strTax =; //总税收格式为
var strShipping =; //总运费格式为
var strOutput =; //要写入页面的字符串
var bDisplay = true; //是否将字符串写入页面(这里是程序员)
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 =< TABLE CLASS = \nopcart \>< TR> +
< TD CLASS = \nopheader \>< B>+ strILabel +< / B>< / TD> +
< TD CLASS = \nopheader \>< B>+ strDLabel +< / B>< / TD> +
< TD CLASS = \nopheader \>< B>+ strQLabel +< / B>< / TD> +
< TD CLASS = \nopheader \>< B>+ strPLabel +< / B>< / TD> +
(DisplayShippingColumn?< TD CLASS = \nopheader \>< B> + strSLabel +< / B>< / TD>:)+
< / TR>;

(i = 1; i <= iNumberOrdered; i ++){
NewOrder =Order。 +我;
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); //产品ID
字段[1] = database.substring(Token0 + 1,Token1); // Quantity
fields [2] = database.substring(Token1 + 1,Token2); // Price
fields [3] = database.substring(Token2 + 1,Token3); //产品名称/描述
fields [4] = database.substring(Token3 + 1,Token4); // Shipping Cost
fields [5] = database.substring(Token4 + 1,database.length); //附加信息

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 + =< TR>< TD CLASS = \nopentry \> +字段[0] +< / TD>;

if(fields [5] ==)
strOutput + =< TD CLASS = \nopentry \> +字段[3] +< / TD>;
else
strOutput + =< TD CLASS = \nopentry \> + fields [3] + - <+ fields [5] +< / I>< / TD>;

strOutput + =< TD CLASS = \nopentry \> +字段[1] +< / TD>;
strOutput + =< TD CLASS = \nopentry \>+ MonetarySymbol + moneyFormat(fields [2])+/ ea< / TD>;

if(DisplayShippingColumn){
if(parseFloat(fields [4])> 0)
strOutput + =< TD CLASS = \nopentry \ " + MonetarySymbol + moneyFormat(fields [4])+/ ea< / TD>;
else
strOutput + =< TD CLASS = \nopentry \> N / A< / TD>;
}

strOutput + =< / TR>;
}

if(AppendItemNumToOutput){
strFooter = i;
} else {
strFooter =;
}
if(PaymentProcessor!=''){
//支付处理器的处理描述字段而不是隐藏值。
//产品的格式描述如下:
// ID,名称,数量X
strPP + = fields [0] +,+ fields [3];
if(fields [5]!=)
strPP + = - + fields [5];
strPP + =,数量。+ fields [1] +\\\
;
} else {
strOutput + =< input type = hidden name = \+ OutputItemId + strFooter +\value = \+ fields [0] +\\ \\ > 中;
strOutput + =< input type = hidden name = \+ OutputItemQuantity + strFooter +\value = \+ fields [1] +\>;
strOutput + =< input type = hidden name = \+ OutputItemPrice + strFooter +\value = \+ fields [2] +\>;
strOutput + =< input type = hidden name = \+ OutputItemName + strFooter +\value = \+ fields [3] +\>;
strOutput + =< input type = hidden name = \+ OutputItemShipping + strFooter +\value = \+ fields [4] +\>;
strOutput + =< input type = hidden name = \+ OutputItemAddtlInfo + strFooter +\value = \+ fields [5] +\>;

$ b}

if(bDisplay){
strOutput + =< TR>< TD CLASS = \noptotal \ COLSPAN = 3>< B>+ strSUB +< / B>< / TD>;
strOutput + =< TD CLASS = \noptotal \COLSPAN = 2 ALIGN = RIGHT>< B> + MonetarySymbol + strTotal +< / B>< / TD>;
strOutput + =< / TR>; (DisplayShippingRow){
strOutput + =< TR>< TD CLASS = \noptotal \COLSPAN = 3>< B>+ strSHIP +< b> ; / B>< / TD>中;
strOutput + =< TD CLASS = \noptotal \COLSPAN = 2 ALIGN = RIGHT>< B> + MonetarySymbol + strShipping +< / B>< / TD>;
strOutput + =< / TR>; (DisplayTaxRow || TaxByRegion){
strOutput + =< TR>< TD CLASS = \noptotal \COLSPAN = 3><
}

; B> 中+ strTAX + < / B>< / TD>中;
strOutput + =< TD CLASS = \noptotal \COLSPAN = 2 ALIGN = RIGHT>< B> + MonetarySymbol + strTax +< / B>< / TD>;
strOutput + =< / TR>;
}

strOutput + =< TR> strOutput + =< TD CLASS = \noptotal \COLSPAN = 2 ALIGN = RIGHT>< B> + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax))+< / B>< / TD>;
strOutput + =< / TR>;

strOutput + =< / TABLE>;


if(PaymentProcessor =='an'){
//处理Authorize.net WebConnect
strOutput + =< input type = hidden name = \x_Version\value = \3.0 \>;
strOutput + =< input type = hidden name = \x_Show_Form\value = \PAYMENT_FORM \>;
strOutput + =< input type = hidden name = \x_Description \value = \+ strPP +\>;
strOutput + =< input type = hidden name = \x_Amount \value = \+ moneyFormat((fTotal + fShipping + fTax))+\>;
} else if(PaymentProcessor =='wp'){
//为WorldPay处理
strOutput + =< input type = hidden name = \desc\value = \+ strPP +\>;
strOutput + =< input type = hidden name = \amount \value = \+ moneyFormat((fTotal + fShipping + fTax))+\>;
} else if(PaymentProcessor =='lp'){
//处理LinkPoint
strOutput + =< input type = hidden name = \\mode \value = \ fullpay\ >中;
strOutput + =< input type = hidden name = \chargetotal\value = \+ moneyFormat((fTotal + fShipping + fTax))+\>;
strOutput + =< input type = hidden name = \tax \value = \+ MonetarySymbol + strTax +\>;
strOutput + =< input type = hidden name = \subtotal \value = \+ MonetarySymbol + strTotal +\>;
strOutput + =< input type = hidden name = \shipping \value = \+ MonetarySymbol + strShipping +\>;
strOutput + =< input type = hidden name = \desc\value = \+ strPP +\>;
} else {
strOutput + =< input type = hidden name = \+ OutputOrderSubtotal +\value = \+ MonetarySymbol + strTotal +\> ;
strOutput + =< input type = hidden name = \+ OutputOrderShipping +\value = \+ MonetarySymbol + strShipping +\>;
strOutput + =< input type = hidden name = \+ OutputOrderTax +\value = \+ MonetarySymbol + strTax +\>;
strOutput + =< input type = hidden name = \+ OutputOrderTotal +\value = \+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax))+\ >中;
}
}

document.write(strOutput);
document.close();
}

// =================================== ================================== ||
// END NOP Design SmartPost Shopping Cart ||
// ============================================ ========================= ||

我知道这是很多文字和代码,但我认为这不会太难找到一个解决方案,它只是在我的课程中的第一个深入的HTML主题,我希望得到这个工作。

您可以执行以下操作:

  file_put_contents('data.txt',var_export($ _ POST,true),FILE_APPEND); 

这会将$ _POST参数中的所有字段保存到文件中。



var_export($ _ POST,true)的替代方法是json_encode($ _ POST),稍后可以通过Javascript读取,或者您可以格式化一些人类可读文本。



例如把它放在 process.php 中。

 <?php 
// submitButton已发送。
if(isset($ _ POST ['submitButton'])){
//构建一个包含所有已提交字段的字符串。

$ str =--- BEGIN ORDER --- \\\

//对于$ _POST变量中的每个字段,迭代并将它们添加到字符串中。
foreach($ _ POST为$ k => $ v){
$ str。=$ k:$ v \\\
;
}
$ str。=--- END ORDER --- \\\
;

//向用户显示结果
echo $ str;

//将其保存到data.txt
file_put_contents('data.txt',$ str,FILE_APPEND);
} else {
// submitButton未被发送,显示一些错误。
回声请提交一些东西;
}


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.

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.

My checkout code

        <form action="process.php" method ="post">
            <script type="text/javascript">
                CheckoutCart();
            </script>
            <br /><br />
            First Name:     <input type="text" name="first" /><br />
            Last Name:      <input type="text" name="last" /><br />
            Street Address: <input type="text" name="address" /><br />
            Suburb:         <input type="text" name="suburb" /><br />
            State:          <input type="text" name="state" /><br />
            Postcode:       <input type="text" name="postcode" /><br />
            Country:        <input type="text" name="country" /><br />
            Phone Number:   <input type="text" name="phone" /><br />
            Email:          <input type="text" name="email" /><br />

            shop:           <input type="text" name="shop" /><br />
            <br /><br />
            Other form data can go here when you create your prototype cart ...
            <br /><br />

            <input type="submit" name="submitButton" value=" Submit Order " />
        </form>

Input shop is not currently being used, where I have trying to get the order information into

My process.php code

<?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.
}
?>

In an earlier version using this code in the checkout.html. This would email me everything i needed

<!-- Checkout Begin-->
            The items listed below are currently in your shopping cart:

            <form action="mailto:xxxxxxx@example.com" method ="post">
                <script type="text/javascript">
                    CheckoutCart();
                </script>
                <br /><br />
                Name:   <input type="text" name="b_first" />
                        <input type="text" name="b_last" /><br />
                Email:  <input type="text" name="b_email" /><br />
                <br /><br />
                Other form data can go here when you create your prototype cart ...
                <br /><br />

                <input type="submit" value=" Submit Order " />
            </form>
            <!-- Checkout End -->

On clicking the send button I would get this text opening in a new email

ID_1=ID+000&QUANTITY_1=1&PRICE_1=28.99&NAME_1=Cat+Scratcher&SHIPPING_1=4.99&ADDTLINFO_1=&SUBTOTAL=%2428.99&SHIPPING=%244.99&TAX=%240.00&TOTAL=%2433.98&b_first=Jonny&b_last=Smith&b_email=a%40a.com

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?

So far I have just been using trial and error and I'm really not sure what to do next

Here is the checkoutCart function from nopcart.js

//---------------------------------------------------------------------||
// 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 = "<TABLE CLASS=\"nopcart\"><TR>" +
                  "<TD CLASS=\"nopheader\"><B>"+strILabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\"><B>"+strDLabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\"><B>"+strQLabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\"><B>"+strPLabel+"</B></TD>" +
                  (DisplayShippingColumn?"<TD CLASS=\"nopheader\"><B>"+strSLabel+"</B></TD>":"") +
                  "</TR>";

   for ( i = 1; i <= 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 += "<TR><TD CLASS=\"nopentry\">"  + fields[0] + "</TD>";

         if ( fields[5] == "" )
            strOutput += "<TD CLASS=\"nopentry\">"  + fields[3] + "</TD>";
         else
            strOutput += "<TD CLASS=\"nopentry\">"  + fields[3] + " - <I>"+ fields[5] + "</I></TD>";

         strOutput += "<TD CLASS=\"nopentry\">" + fields[1] + "</TD>";
         strOutput += "<TD CLASS=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</TD>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 )
               strOutput += "<TD CLASS=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</TD>";
            else
               strOutput += "<TD CLASS=\"nopentry\">N/A</TD>";
         }

         strOutput += "</TR>";
      }

      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 += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + fields[1] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      } 

   }

   if ( bDisplay ) {
      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strSUB+"</B></TD>";
      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + strTotal + "</B></TD>";
      strOutput += "</TR>";

      if ( DisplayShippingRow ) {
         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strSHIP+"</B></TD>";
         strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + strShipping + "</B></TD>";
         strOutput += "</TR>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strTAX+"</B></TD>";
         strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + strTax + "</B></TD>";
         strOutput += "</TR>";
      }

      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strTOT+"</B></TD>";
      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</B></TD>";
      strOutput += "</TR>";

      strOutput += "</TABLE>";


      if ( PaymentProcessor == 'an') {
         //Process this for Authorize.net WebConnect
         strOutput += "<input type=hidden name=\"x_Version\" value=\"3.0\">";
         strOutput += "<input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\">";
         strOutput += "<input type=hidden name=\"x_Description\" value=\""+ strPP + "\">";
         strOutput += "<input type=hidden name=\"x_Amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      } else if ( PaymentProcessor == 'wp') {
         //Process this for WorldPay
         strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
         strOutput += "<input type=hidden name=\"amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      } else if ( PaymentProcessor == 'lp') {
         //Process this for LinkPoint         
         strOutput += "<input type=hidden name=\"mode\" value=\"fullpay\">";
         strOutput += "<input type=hidden name=\"chargetotal\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
         strOutput += "<input type=hidden name=\"tax\" value=\""+ MonetarySymbol + strTax + "\">";
         strOutput += "<input type=hidden name=\"subtotal\" value=\""+ MonetarySymbol + strTotal + "\">";
         strOutput += "<input type=hidden name=\"shipping\" value=\""+ MonetarySymbol + strShipping + "\">";
         strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
      } else {
         strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ MonetarySymbol + strTax + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\">";
      }
   }

   document.write(strOutput);
   document.close();
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||

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.

解决方案

You could do something like

file_put_contents('data.txt', var_export($_POST, true), FILE_APPEND);

That would save all fields in the $_POST parameter to the file.

An alternatives to var_export($_POST, true) is json_encode($_POST) which can be read by Javascript later, or you can format some human readable text instead.

For example put this in your process.php.

<?php
// submitButton was sent.
if(isset($_POST['submitButton'])) {
    // Build a string with all fields that was submitted.

    $str = "--- BEGIN ORDER ---\n"
    // For each field in the $_POST variable, iterate and add them to the string.
    foreach($_POST as $k => $v) {
        $str .= "$k: $v\n";
    }
    $str .= "--- END ORDER ---\n";

    // Show the user the result
    echo $str;

    // Also save it to data.txt
    file_put_contents('data.txt', $str, FILE_APPEND);
} else {
    // submitButton was not sent, show some error.
    echo "Please submit something";
}

这篇关于将JavaScript传递到使用PHP的.txt文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆