SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Nov 2007
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question convert the javascript variable into php

    am trying to get the javascript variables from the pay pal form into php variables to be able to insert it into the database
    any ideas?
    i tried to echo the name of the input ,ex:echo $amount ,but it never worked
    HTML Code:
    function Xbild () {         // build the PayPal FORM
    var inp = '<input type="text" name=';
    var inp1 = '<input type="hidden" name=';
    var ary1 = new Array ();
    var ary2 = new Array ();
    var i,j,pc,sx;
    var tot  = 0;               // price total
    var frst = 1;               //  1st time thru marker
    var str  = "";              // temp string
    var disc = new Array ();    // price per item to subtract for discount
    var tmps = root.stxt0+" "+ttxt+" "+ctxt;  // the shipping text
    
      if (bmisc.length > 0) {            // apply misc codes
        ary1 = bmisc.split ("&");        // individual commands
        for (i=0; i<ary1.length; i++) {  // process individual entries
          if (ary1(i).length > 0) {      //  but only if something there
            ary2 = ary1[i].split ("=");  // get parts
            document.writeln (inp, '"', ary2[0], // build line
              '" value="', ary2[1], '" />');
          }
        }
      }
    
      if (ttax > 0)             // do we have a calculated tax
        document.writeln (inp1, '"tax_cart" value="', Dollar(ttax), '" />');
      for (i=0; i<cats; i++) {  // set item discounts
        disc[i] = ctot["d" + i] / ctot["a" + i];  // % discount per item
      }
    
      j = 0;       // starting suffix
      for (i=1; i<cmax; i++) {  // run all the data cookies
        cook = new Cookie (document, "paycart" + i);
        cook.load();         // get contents
        if (cook.qty > 0) {  // something here
          j = j + 1;         // bump suffix
          document.writeln (inp, '"quantity_', 
            j, '" value="', cook.qty, '" />');
          document.writeln (inp, '"item_name_', 
            j, '" value="', cook.des, cook.adtx, '" />');
          document.writeln (inp, '"amount_',
            j, '" value="', Dollar (cook.prc * (1.0 - disc[cook.pcat]) + cook.ader/cook.qty), '" />');
          if (gwtot > 0 && frst > 0) str = ', GIFT-WRAP';
          if (cook.op1n.length > 0) {    // 1st option present
            document.writeln (inp1, '"on0_',
              j, '" value="', cook.op1n, '" />');
            document.writeln (inp1, '"os0_',
              j, '" value="', cook.op1v + ', ' + tmps, '" />');
          } else if (tmps.length > 0) {
            document.writeln (inp1, '"on0_',
              j, '" value="Shipping" />');
            document.writeln (inp1, '"os0_',
              j, '" value="', tmps, str, '" />');
          }
          tmps = "";  // zap it
          str  = "";
    
          if (cook.op2n.length > 0) {    // 2nd option present
            document.writeln (inp1, '"on1_',
              j, '" value="', cook.op2n, '" />');
            document.writeln (inp1, '"os1_',
              j, '" value="', cook.op2v, '" />');
          }
          if (cook.cod != "")
            document.writeln (inp, '"item_number_',
              j, '" value="',cook.cod, '" />');
          if (frst > 0 && (hand > 0 || insx > 0 || gwtot > 0)) {
            document.writeln (inp1, '"handling_',
              j,'" value="', Dollar (hand*1.0 + insx*1.0 + gwtot*tqty), '" />');
          }
          if (frst > 0 && ship > 0) 
            document.writeln (inp1, '"shipping_',
              j, '" value="', Dollar (ship), '" />');
          else
            document.writeln (inp1, '"shipping_',
              j, '" value="0" />');
    
          frst = 0;  // set to false - true only on 1st item
        }
      }
    }

  2. #2
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The only way to do it is to create a form with hidden fields that points to a php page, and submit it. You can also do this with AJAX. It isn't immune from people being able to modify the value though, not entirely secure.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2007
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its already in a paypal form in a php file
    my problem is how to get all these variables into php variables to insert them in the database,so the admin,knows who have bought what?!
    how can i ?

    [html]
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post"
    name="ppform">
    <p>
    <input type="hidden" name="cmd" value="_cart" />
    <input type="hidden" name="upload" value="1" />

    <script type="text/javascript">
    <!--
    var inp = '<input type="hidden" name=';
    // Output any header data...
    document.writeln (inp, '"business" value="', root.xx_id, '" />');
    if (root.xx_bn.length > 0) { // record business number
    document.writeln (inp, '"bn" value="', root.xx_bn, '" />');
    }
    if (root.xx_cbt.length > 0) { // record continue button text
    document.writeln (inp, '"cbt" value="', root.xx_cbt, '" />');
    }
    if (root.xx_cur.length > 0) { // record currency entry
    document.writeln (inp, '"currency_code" value="', root.xx_cur, '" />');
    }
    if (root.xx_lc.length > 0) { // record user entry
    document.writeln (inp, '"lc" value="', root.xx_lc, '" />');
    }
    if (root.xx_can.length > 0) { // set cancel return path
    document.writeln (inp, '"cancel_return" value="', root.xx_can, '" />');
    }
    if (root.xx_ret.length > 0) { // set return path
    document.writeln (inp, '"return" value="', root.xx_ret, '" />');
    }
    if (root.xx_sty.length > 0) { // set display style
    document.writeln (inp, '"page_style" value="', root.xx_sty, '" />');
    }
    if (root.cval.length > 0) { // set coupon value selected
    document.writeln (inp, '"custom" value="', root.xx_ctxt, '" />');
    }

    // Now, send out the items in the cookies...
    Xbild ();

    //-->
    </script>
    </p>
    </form>
    [html]

  4. #4
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    With paypal, you can probably use their callback to call a php file with the appropriate information. I think you can pass them order numbers and things, so you insert it into the db, get the order number, then the callback will update that order to say it has been paid.

  5. #5
    SitePoint Addict
    Join Date
    Nov 2007
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what do u mean by a call back???please could u give me more details

  6. #6
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The callback is a script on your server that you can set paypal to call when the order is complete. You'll have to look at the paypal documentation to find the details, but I know it exists.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •