submit form to other site... in background (or whatever)?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

submit form to other site... in background (or whatever)?

Post by Skara »

Ok, here's what I need to figure out how to do.
I need to be able to fill out a form that submits the data to one site, then redirects (or whatever) to another site.
In other words...
> I fill out form.
> I click submit.
> Data goes to foo.com/page.php
> I go to bar.com

This possible?
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

Post by partiallynothing »

Try looking into the header function http://php.net/header

Here is an example:

Code: Select all

<?php
// Process post data
header('Location: http://bar.com/'); // Redirect user
?>
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

ok, but how would I send the data somewhere else? There are three locations here: my script, the site the data is sent to, and where I'm redirected to. In other words, I need something like this:

if (submitted) {
send code
redirect
} else print(form);
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

re

Post by harrisonad »

yourform.php submit to processing.php, then processing.php will redirect it to otherplace.php

dig it
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

ok, you guys still aren't getting what I mean... Ok, let me re-explain yet again.

I have control over page A. page B is NOT under my control in any way. the same for page C.
In other words, it might look like this:

me.com/form.php =>DATA=> foo.com/processing.php
\\=>REDIRECT=> bar.com/view.php

Again, I have no control over the page I want the data sent to. :/
jmrdeuce32
Forum Newbie
Posts: 15
Joined: Wed Apr 27, 2005 5:45 pm
Location: Naples, FL

Post by jmrdeuce32 »

Where is the data going in the page you are sending it to?...Does it know to look for the data?....Does the data change between the first and second pages?...

If the second page is accepting dat use variables like $_POST or $_GET depending on what the page is looking for.

I don't know how you would be redirected from the second page to the third if you don't have any control over the second.

You may be able to have the form open a new window with the second page as well as redirect to the third page in the main window.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

set the action to the site you want it to go to. This can be dynamically changed with javascript.

You can always use curl()
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

ok, curl's giving me a headache. Does this look anything close to right?

Code: Select all

$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,"http://foo.com/process.php");
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "var={$_GET['var']}");
  curl_exec($ch);
  curl_close($ch);
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

just pop a new window and target the post to the new window

Code: Select all

<script language=&quote;Javascript&quote;>
<!-- //
function popIt(){
    window.open('','windowfoo','toolbar=0,menubar=0,scrollbars=0,resizable=0,width=1,height=1');
    document.theform.target = 'windowfoo';
    document.theform.submit();
}
// -->
</script>
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

yes, but I don't want to SEE the processing page... That's the whole point of this script. ;)
Post Reply