Sending data from a form to two seperate pages?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpmike
    New Member
    • May 2007
    • 5

    Sending data from a form to two seperate pages?

    I have a simple form and would like the data sent to two different pages. Actually I only need the data sent to one page and the user sent to another page.
    For example user is at page1.php (which contains the form). Once the user submits the form, the data is sent to page2.php and the user is redirected to page3.php.

    This is most likely a javascript solution but since I'm always using php I figured I'd post it here.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Once you're finished processing the form data, use a header redirect:

    [code=php]
    header('Locatio n: page3.php');
    exit;
    [/code]

    Note that this will only work if your script *does not output ANYTHING to the browser*! This includes any leading spaces before the first <?php tag in your document.

    Comment

    • phpmike
      New Member
      • May 2007
      • 5

      #3
      Originally posted by pbmods
      Once you're finished processing the form data, use a header redirect:

      [code=php]
      header('Locatio n: page3.php');
      exit;
      [/code]

      Note that this will only work if your script *does not output ANYTHING to the browser*! This includes any leading spaces before the first <?php tag in your document.

      Yes that would work. But unfortunately I would like to post to someone elses site but have my user go to one of my pages.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Originally posted by phpmike
        Yes that would work. But unfortunately I would like to post to someone elses site but have my user go to one of my pages.
        Ah. Well then, you'll be wanting to use either cURL or fopen, depending on how you need to send the data. If it s/b POST'd, then you'll have to use cURL, and I know just about nothing about it. Though there is a pretty good resource here.

        If you can pass the variables via GET, then you can use file_get_conten ts to send the form variables, something like this:

        [code=php]
        $response = file_get_conten ts("http://somesite.dom/formprocessor.p hp?var1=val1&yo u=get&the=idea" , 'r');
        [/code]

        Then parse $response (or whatever you decided to call it ~_^) to verify a correct submission, and redirect on success.

        Comment

        Working...