[thelist] calling a php file and submitting a form? (send POST vars in PHP?)

shawn allen shawn at alterior.net
Wed Jan 8 16:25:15 CST 2003


quoth Tom Dell'Aringa:
> --- Mike Migurski <mike at saturn5.com> wrote:
> > Shawn's method is better - do whatever you need to do in PHP, and
> > then generate a POST or GET request from within PHP. GET is easier
> > of course, so use that if the remote script supports it. POST
> > shouldn't be too difficult though. (I say this never having done it
> > before :)
>
> Well, I can't use GET since cart.bok wants POST and I can't change it.
> (If it was GET I'd have other options too).
>
> I actually tried doing an HTTP post from an intermediate page with no
> success, and I'm not keen on spending a ton of time on that.

I didn't realize this was for a shopping cart. Forming your own POST
request that jives with the cart's need for cookies and such could be a
huge PITA. I'd say ditch that idea.

> I have however submitted the form to the same page, then picking up on
> the submit name (submit=add to cart) I pop into an if clause.
>
> From there I used header("location: cart.bok"); which sent me right
> there..which is great. Now I just need to send the POST vars along
> with it.

Yeah, that won't work. Redirects get a whole new set of headers, and
ditch the rest of the request (all the POST vars, in your case).

I guess the question is, why do you need to submit your cart data to 2
different locations? Are you doing your own handling, or is it just so
you can modify the appearance of the submission document? If that's the
case, you might want to look into customizing the application somehow,
if possible.

Failing that, a potential solution using some simple javascript:

- start a form that will submit to the cart URI
- generate a series of hidden form inputs that duplicate the $_POST
  array (if you're submitting nested arrays, a recursive function should
  handle this task well)
- use an event handler (onload) to submit the form as soon as possible
- for the javascript-handicapped (or folks with onload disabled),
  provide just a single submit button that takes them to the cart,
  along with an apologetic statement describing the need for the
  duplicate submission :)

HTH,
--
shawn allen
  mailto://shawn@alterior.net
  phone://415.577.3961
  http://alterior.net
  aim://shawnpallen




More information about the thelist mailing list