Jump to content

Post data and redirect to other domain


menwn

Recommended Posts

Hello all,

 

I have this issue: I have a form with several fields. I need to save to a session variable (in submit page) all of the fields upon submit and then post some of the fields to a https site using a POST request (i.e., doing a header('Location: https://mynewdomain.com/page.cfm?'.$data) won't cut it).

 

Now, I can do it with javascript... a whole bunch of hidden fields in the between page and then auto submit the form to the mynewdomain.com domain using the post method.

 

I am wondering whether there would be a better way for that. I know that Curl does it, with one glitch. When I set the parameter CURLOPT_FOLLOWLOCATION to true it redirects the user BUT it doesn't load any css or javascript from the new page. People say on the web to do a request for each file but I haven't figured out how to do it.

 

Can anyone post an elegant/concrete solution to this problem or should I resort to Javascript?

 

Thanks

menwn

Link to comment
Share on other sites

You can't submit data on behalf of the user. You have to make their browser do it, and that means writing a

. If you don't want the user to have to click something then you'll need JavaScript to submit the form.

 

Using cURL means you have your server submit the data. If you echo the output (like if you don't use CURLOPT_RETURNTRANSFER) then the browser will think the HTML you're sending is from your server, not someplace else. You can try to insert a but that's a hack, not a solution.

 

So basically,

or should I resort to Javascript?

Yeah. I, for one, would not use JavaScript to submit the form - I'd tell the user to click a button or whatever to continue.

Link to comment
Share on other sites

Hi,

 

thanks for the response. So Curl is mostly for services I take it right? Exchanging information between server in the back scene.

 

Well, I thought that there should a be a way to redirect after posting data on behalf of the user. I mean once he has already posted it through a visible form.

 

I don't think that having a button is a good idea. Because it would require from the user to click a button he doesn't see the reason for. After all he just clicked one for the exact purpose of sending his information to the next step. I have a <noscript> tag with a submit button and I let them know why they are seeing this but I definitely use javascript submission as the default.

 

No it even fsocket wouldn't do the trick? 

 

Thank you,

menwn

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.