De Paragon
De Paragon

Reputation: 73

How can I send form data to another server and capture the output and display it as message

I want to submit form data to another url (website on another server) capture the success or failure message (server output) and reply back on the form webpage.

This I want to achieve without letting the user know that the data was actually posted to another website.

       echo "
      <html>
       <body>
       <form action ='http://www.example.com/processor.php' method ='POST' >
        <input type ='hidden' value ='official' name = 'name'/>
          <input type ='hidden' value ='official2' name = 'email'/>
          <input type ='hidden' value ='official3' name = 'contactTime'/>
          <label for 'other info'> Enter details here </label> <br/>
      <textarea rows='4' cols='50' name ='other info' maxlength='200'></textarea>

       <input type ='hidden' value ='official4' name = 'legalId'/> 
     </br>
      <input type = 'submit' name = 'submit' value ='Send'/>
  </form>
  </body>
 </html>
"; 
// I want to send the data to http://example.com/processor.php
  ?> 

I have successfully sent this data to http://example.com/processor.php and success integer "2" was displayed on the page. I don't want this page to be seen by my site visitors. I want to capture this success integer from the other server and display it as a message to the user on my own website.

Upvotes: 1

Views: 3662

Answers (2)

Tom Hallam
Tom Hallam

Reputation: 1950

I think a good idea would be to look into cURL, you can accept the data into a PHP form then use cURL to call the remote site with the $_POST data, reading the information back.

There is a good tutorial here: http://davidwalsh.name/curl-post

Upvotes: 0

beerwin
beerwin

Reputation: 10327

Don't submit your form to the http://example.com/processor.php directly. Submit the form to your own file, which should do the following:

  1. Collect the post data you submitted
  2. Post the data you collected using CURL to http://example.com/processor.php
  3. CURL should return the response page the remote server generated to you
  4. Extract the result from the returned page
  5. Do with them whatever you like (display them , store them in a database, etc)

Upvotes: 1

Related Questions