Forum Moderators: open

Message Too Old, No Replies

js cookie problem. printing multi values

         

indiguy

5:57 am on Oct 6, 2009 (gmt 0)

10+ Year Member




main page (from a form)
------------

function set_cookie(){
var total = document.order.GrandTotal.value;
var items = document.order.Cart.value;
var stuff_for_cookie = total + "///" + items;

document.cookie = escape(stuff_for_cookie);
}

next page (with contact form)
<script type="text/javascript">
var cookie_stuff = unescape(document.cookie);
var crumbs = cookie_stuff.split("///");
var total = crumbs[0];
var items = crumbs[1];
</script>
<?php $total = $_POST['total']; ?>
<script language="JavaScript">document.write(total)</script>
<?php //$item = $_POST['item']; ?>
<script language="JavaScript">document.write(items)</script>
<?php

What im doing it passing the total and multi items from a menu page into the contact form.
With the about code, i get the total, but it wont pass into a php veriable:
$total = $_POST['total'];
//shopping results
$message = " $todayis [EST] \n
Attention: $attn \n \n
Message: $message \n \n
Order Items: $items \n
Total Price: $total \n
";

the $total = $_POST['total']; does nothing, ive also tried $_GET... nothing displaying, the variable is still empty.

The Cart ( var items = document.order.Cart.value; )
how can i get the list displaying from that? is it a while loop, an array?

Im totally new javascript :s

Thanks to anyone who can help.. :D

daveVk

6:54 am on Oct 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the html page within the form you are posting

<input type="hidden" name="total" id="total" value="" />

var total = crumbs[0];
becomes
document.getElementById("total").value = crumbs[0];

ditto for items.

indiguy

9:33 am on Oct 6, 2009 (gmt 0)

10+ Year Member



tried that, nothing.. (sorry i was really tired writing that main post on the forum

maybe im doing something wrong~
----
but it wont pass into a php veriable:
$total = $_POST['total'];
//shopping results
$message = " $todayis [EST] \n
Attention: $attn \n \n
Message: $message \n \n
Order Items: $items \n
Total Price: $total \n
";
this code is after i submit the contact form. I was trying to use the cookie to pass the values into that. as you can see with the 'total' var.

the bottom code is on the same page, (after contact has been submitted.. using isset..)
next page (after contact form)
<script type="text/javascript">
var cookie_stuff = unescape(document.cookie);
var crumbs = cookie_stuff.split("///");
var total = crumbs[0];
var items = crumbs[1];
</script>
<?php $total = $_POST['total']; ?>
<script language="JavaScript">document.write(total)</script>
<?php //$item = $_POST['item']; ?>
<script language="JavaScript">document.write(items)</script>
<?php

So what im trying to do, is with these codes, passing the values from the user interaction menu to select items, then it passes it into a cookie, they submit the menu page, then the contact form opens, after submitting that, it sends email and opens (for testing) a page. Its this page where i have this code to try open the cookie, and send the values into $... vars to connect to the message (email) so they can see what they have ordered.
Hope this clears it up. There is not <form> on this page.

daveVk

12:53 pm on Oct 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it sends email and opens (for testing) a page. Its this page where i have this code to try open the cookie, and send the values into $... vars.

You have a page say test.php in which you need $total, that needs to come from the url get/post request, or from the php code reading the cookie directly, you can not use js to get it because the js is not executed on the server.

So look at where test.php is opened, can it be opened as "test.php?total="+total ?

If that is not possible I guess php can read the cookie, I have no experience of doing that.