View Full Version : Passing variables to form- adding multiple items automaticly

07-16-2007, 12:53 AM
I'm creating a type of shopping cart/order form for a client, a very simple one.

So far I've been able to pass variables into a form on a different page using a getData function. Basically this lets me assign variables in a link that the customer clicks. When they click the link they're brought to the orderform page and see that the data from the item they picked is already filled into the form (the item type and design are specified via a drop-down list and a textfield).

Now I'd like to expand this little project so that when a customer clicks the item and their order is filled out, they can have the option of continuing to shop. (the orderform would need to be saved. via cookie?)

In order for this to work I'm also going to have to somehow make the script work so that if an item is already specified and the customer clicks another link, a new item will be added.

I know what i want to do... I just have no idea how to get there. I don't know much about PHP, but would like to attempt this anyhow.

Here is my code so far:

<script type="text/javascript">
var dataPassed = ''

function getData(){
if (location.search.length > 0){
dataPassed = unescape(location.search.substring(1))

tempArray=dataPassed.split("=") // create the array tempArray


<form method="post" name="form" action="order_process.php">
<label>Item 1</label>
<select name="item" value=""><option>Please Select</option><option value="Flowerpot" name="Flowerpot">Flowerpot</option><option value="Birdhouse"

<input type="text" name="design" value="" style="width:350px;"/>

07-16-2007, 02:23 PM
I think it's noble of you to attempt this yourself, probably a good learning
experience with PHP, but if your final goal is an actual working shopping cart
that you will be using, I really do suggest customizing an existing PHP/MySQL
script (like CubeCart) .... something that's free, and you can mess around with.

But, I found this using Google:

I don't know which example is the best because I've never taken the time
to code my own cart ... it's just not worth the effort (my personal opinion).

07-17-2007, 05:48 PM
I'm actually looking for more of an orderform- it's just going to 'appear' to be a shopping cart....

Right now I think I'm going to scale back to only having an "add more items" option which populates more fields.

Anyone know of a good tutorial to allow me to do that?