Forum Moderators: coopster

Message Too Old, No Replies

Intercept POST to form and record data

How to record data when a form is posted

         

ruthjanette

1:56 pm on Nov 16, 2007 (gmt 0)

10+ Year Member



I've been trying to figure this out and googling for answers and still can't figure it out. I would appreciate any insight you all can provide, I'm pretty stumped. I'm happy to code a solution in either PHP or Perl, my server is Unix.

The issue is this:
I have a 3'rd party shopping cart for my e-commerce site that has no way for me to see cart activity. Fine, I say, I'll just "intercept" the submit button on my "add to cart" form with a script, write a line to file and then have the script send the form happily on its way and I'll have data I can use to track activity.

Not that simple I've learned. I can set the "add to cart" form to submit to my php script, and use curl to submit the form and pass the POST parameters but the Location URL is still on my site pointing to my script. Because the base url is my site other relative links on the shopping cart now fail, no good. Oh, and yes, the form must be submitted as POST.

So, I say, just do a redirect instead. Nope, works in GET, not in POST (for me anyway).

So I figure I go back to submit the form as POST in curl and then redirect to a "view cart". Of all things, the cart shows OTHER contents, not what I put in. It's as though there are 2 carts now, one for my script submitted form requests and another for browser submitted requests. It must be keying off of something, I thought it would be agent or IP but I'm passing USER_AGENT through in my script.

So, am I missing some really key point here?

I'm an old C/Perl coder, new to PHP so I'm still relying on examples to muddle my way through. I've been quite unable to find a good example of this though, not sure why it seems like a pretty ordinary thing to do.

Can somebody please point me in the right direction? TIA.

phranque

3:18 pm on Nov 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], ruthjanette!

perhaps you could use the onclick trigger of the submit button get some javascript to do something...

d40sithui

5:08 pm on Nov 16, 2007 (gmt 0)

10+ Year Member



im a little confused by your problem.
how does the 3rd party cart work, i mean, how does it store items and retrieve items? i ask becuase you're somehow seeing two carts?
also, by "cart activity" do you mean seeing the cart contents?

ruthjanette

3:12 am on Nov 17, 2007 (gmt 0)

10+ Year Member



Hi.

Thank you for the ideas. I've thought about Javascript, normally I shy away from it in favor of server-side work. It is an idea though...

I don't really know how the 3'rd party cart works exactly, it's a black box to me. On my site is an html form which has hidden variables for things such as item name, price, weight, etc and upon the form submit (POST) the form calls the 3'rd party server, in this a cold fusion script which places the item in the cart and displays a page back that is the cart contents. The shopping cart is typical of hosted carts, it's not on my server, it's on theirs and it takes a basic form POST submittal. There's a different call to do a view cart. I don't know if I can mention the name here since I'm new to the forum and it's not my intention to plug or dis anyone.

The goal is simple, since the POST goes away to another server, the only shot I've got at squirreling away a little intelligence data for myself about items placed in my cart on that other server is to 'intercept' them as they push the add to cart form leaving my server to go to the cart. But I just can't figure out how to do that intercept correctly.

Thank you for your consideration.

Peace,
Ruth

phranque

3:42 am on Nov 17, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can't really learn or do anything until the form elements have all been set and the form has been submitted.
you can't intercept and redirect the POST.
therefore, your only chance is to use the submit to trigger some ajax.
you don't really care what is returned by your asynchronous request.
you just want your trigger to return a submit value after it goes off to do its thing with your server and then the usual HTTP POST mechanism for the form will go to the cart server.