RePOSTing form data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dbws
    New Member
    • Mar 2008
    • 6

    RePOSTing form data

    Hi folks,

    I am working on a registration form that records its data in a database on our Web site then forwards the user to another site's page where fee processing occurs. The other site's page uses POST data from my form to populate its fields and records.

    How do I get my site to send POST data again to the other site after the user has already clicked the Submit button on my end and it has been sent to one of my pages for processing?

    Thanks in advance!
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You could populate some hidden inputs in a form with the post data, then send the form to the other website.

    Comment

    • RoninOni
      New Member
      • Mar 2008
      • 9

      #3
      Must say I don't clearly understand your situation

      Do you control the other site?
      Are you reffering to the customer filling out your form, submitting, then leaving your site to go to a site you do not control, then comming back and having the info?

      If the second scenario is closer to your situation, I would store all the post variables into session vars, then on any page you want you can check if they are set, and prepoulate either hidden (as stated above) or visible fields with their values.

      Comment

      • dbws
        New Member
        • Mar 2008
        • 6

        #4
        Originally posted by markusn00b
        You could populate some hidden inputs in a form with the post data, then send the form to the other website.
        How do you get the hidden inputs to resubmit without requiring a user to click on a Submit button?

        Comment

        • dbws
          New Member
          • Mar 2008
          • 6

          #5
          Originally posted by RoninOni
          Must say I don't clearly understand your situation

          Do you control the other site?
          Are you reffering to the customer filling out your form, submitting, then leaving your site to go to a site you do not control, then comming back and having the info?

          If the second scenario is closer to your situation, I would store all the post variables into session vars, then on any page you want you can check if they are set, and prepoulate either hidden (as stated above) or visible fields with their values.
          Hi RoninOni.

          The assumption here is that two sites are controlled by two different parties: our Web site is controlled by me and the payment processing site is controlled by a known corporation.

          I have had no problem sending POST data to the site and receiving POSTBACK data. The problem is with being able to process the data and send the same data to the external site. To process my data, a user clicks the Submit button and the POST data is sent to the page specified in the action of the form tag. My question is how do I take the same data from the page the data is sent to and send it to the external site as POST data without requiring a user to click another Submit button?

          Would session variables work with the external site as well? Or would that require the external site coding their page to accept session variables instead of POST variables? (Is there a difference?)

          Many thanks!

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by dbws
            How do you get the hidden inputs to resubmit without requiring a user to click on a Submit button?
            You could use javascript :)

            [code=javascript]
            formname.submit ()
            [/code]

            Comment

            • dbws
              New Member
              • Mar 2008
              • 6

              #7
              Originally posted by markusn00b
              You could use javascript :)

              [code=javascript]
              formname.submit ()
              [/code]
              Is there a way to do this without Javascript?

              Thanks!

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                Originally posted by dbws
                Is there a way to do this without Javascript?

                Thanks!
                OK, let's say your form page (user input) is called form.php
                The processing file where the information initially gets sent is called info.php
                The secondary processing file is called other.php

                How does the other.php file accept variables? is it by POST? Maybe have an if statement in the form.php page which will test to see if a variable has been set by info.php (you can write at the bottom of info.php $info_sent = TRUE; and then test for it etc...) and have a hidden form (just a normal form with a single hidden field) that will refresh itself and automatically send the information?

                Can I just ask, who is the information going to? You and...

                Comment

                • dbws
                  New Member
                  • Mar 2008
                  • 6

                  #9
                  Originally posted by TheServant
                  OK, let's say your form page (user input) is called form.php
                  The processing file where the information initially gets sent is called info.php
                  The secondary processing file is called other.php

                  How does the other.php file accept variables? is it by POST? Maybe have an if statement in the form.php page which will test to see if a variable has been set by info.php (you can write at the bottom of info.php $info_sent = TRUE; and then test for it etc...) and have a hidden form (just a normal form with a single hidden field) that will refresh itself and automatically send the information?

                  Can I just ask, who is the information going to? You and...
                  Hi TheServant,

                  The information is going to a financial institution. Their page accepts POST data by having a form submit that information like this:

                  Code:
                  <form action="http://www.financialinstitution.com/processpayment" method="post">
                  But the problem is that I need to process the data on my site first like this:

                  Code:
                  <form action="process.php" method="post">
                  Both pages accept variables by POST. So, if I can do what you suggest (i.e., use a hidden form to send the information automatically after my processing has occurred), then that is the solution I need. But I do not know how to use a hidden form and automatically send the information *without* using Javascript. Do you have any suggestions?

                  Thanks in advance!

                  Comment

                  • ronverdonk
                    Recognized Expert Specialist
                    • Jul 2006
                    • 4259

                    #10
                    Imagine the following process:
                    Code:
                     1. Your form script:
                        - user fills in form
                        - user submit to your processing script
                     2. your processing script:
                        - save $_POST array in $your_array
                        - process the posted form
                        - build a cURL POST request with $your_array as POST
                        - submit cURL post request to financial institution    
                     3. Financial institution:
                        - process POSTed variables
                    Is this the process you want?

                    Ronald

                    Comment

                    • dbws
                      New Member
                      • Mar 2008
                      • 6

                      #11
                      Originally posted by ronverdonk
                      Imagine the following process:
                      Code:
                       1. Your form script:
                          - user fills in form
                          - user submit to your processing script
                       2. your processing script:
                          - save $_POST array in $your_array
                          - process the posted form
                          - build a cURL POST request with $your_array as POST
                          - submit cURL post request to financial institution    
                       3. Financial institution:
                          - process POSTed variables
                      Is this the process you want?

                      Ronald
                      Hi Ronald,

                      Yes! That is the process I am looking for.

                      What is a cURL POST? Can you point me to an example? In the meantime, I'll be checking the Web to see what it is and how to use it in this context.

                      Thanks again!

                      Comment

                      • ronverdonk
                        Recognized Expert Specialist
                        • Jul 2006
                        • 4259

                        #12
                        See also CURL, Client Url Library Functions in the php documentation.

                        Following are 2 examples on how you can use cURL to POST data. The first one builds a string, like a url string. The second one posts the variables from an array. The latter can be used when you (in your POST processing script) just assign the $_POST array to your array.

                        1. Post a url-like stream
                        [php]
                        <?php
                        // POST a stream via cURL

                        $ch = curl_init();

                        curl_setopt($ch , CURLOPT_URL,"ht tp://www.mysite.com/tester.php");
                        curl_setopt($ch , CURLOPT_POST, 1);
                        curl_setopt($ch , CURLOPT_POSTFIE LDS,
                        "postvar1=value 1&postvar2=valu e2&postvar3=val ue3");
                        curl_exec ($ch);
                        curl_close ($ch);
                        ?>
                        [/php]2. Here you POST an array (like you have) via cURL[php]
                        <?php
                        // ------------ POST an array via curl -----------------------

                        // create a new curl resource
                        $ch = curl_init();

                        // set URL and other appropriate options
                        curl_setopt($ch , CURLOPT_URL, "http://path/to/your/page.php");
                        $id=111; $code='ABCD';

                        // Build the test array
                        $data=array( 'id'=>$id, 'code'=>'$code' );

                        // Do a POST
                        curl_setopt($ch , CURLOPT_POST, true);
                        curl_setopt($ch , CURLOPT_POSTFIE LDS, $data);

                        // grab URL, and print
                        curl_exec($ch);

                        ?>[/php]Ronald

                        Comment

                        Working...