wojodesign / simplecart-js

A simple javascript shopping cart that easily integrates with your current website.
simplecartjs.org
1.79k stars 490 forks source link

question about ,sendform extra_dada #489

Open kang1987 opened 10 years ago

kang1987 commented 10 years ago

< input type="text" name="text" id="text" value="123" /> simpleCart({ checkout:{ type: "SendForm", url:"/Home/Mall/checkout", method:"GET", extra_data:{ text: ????? , }, }, }); How can i get the text's value by using simplecart?

irsah commented 9 years ago

There are several examples in this repo by contributors/users. Click this repo "Label" section and you can find some good answers + examples by their categories...

Anyway you can " bind " additional text/strings with simplecart " beforeCheckout " functions for form fields like so:-

javascript ..your code .. extra_data:{ // grabs the "id=text" value text:document.getElementById("text").value, },


Then bind the `" id=text "` value to simpleCart before sending the `data(value)`:-

``` javscript
simpleCart.bind ( 'beforeCheckout' , function( data ) { 
data.text = document.getElementById("text").value;
});

For post methods, echo out the receiving end using $_POST['text'] to grab the values which is " 123 ".

A working example would be here at http://blogrcart-mukabuku.blogspot.com/ . View the page source at the send order email form (checkout). The theme is using simpleCart 3.++ (think so. Hope it helps :-)

kang1987 commented 9 years ago

@irsah Im chinese , my english is bad, thank you very much for asking my question ,it is helpful !!!

irsah commented 9 years ago

@kang1987 your most welcome :-)