0

I have a small affiliate network and one of my offers, I have a form for it where I am collecting page viewer data for my own records, I then want to post that data to ANOTHER form automatically so the people do not need to complete the same information twice.

How would I do this?

I googled for nearly an hour and couldn't find anything.

The page can be viewed here

http://getthiscrazyoffer.com/jobs/index.php

2 Answers2

0

There are two good ways to do this:

Way one: switch your page to using AJAX. You can make two AJAX requests: one to each PHP file.

Way two: You can use the cURL plugin for PHP to make GET and POST requests automatically from the server; thus you can send the data to the PHP file for the other form. In particular, for POST requests, you'll need to:

  1. Use $curl = curl_init(url) to generate a request
  2. use curl_setopt($curl, CURLOPT_POST, true) to make it a POST request
  3. use curl_setopt($curl, CURLOPT_POSTFIELDS, $data), where $data contains the form field values which the other form can retrieve via $_POST
  4. Use curl_exec to run the request.
jasonhansel
  • 642
  • 9
  • 14
  • the thing is, i dont "control" the other form, one form belongs to me - the other to another company, is that going to be an issue? – user3147299 Aug 03 '14 at 05:10
  • It might be an issue if you use "way one" as listed in my answer, since cross-domain AJAX (generally) isn't possible. But "way two" should work, as long as you can find out the names of the relevant form fields so that you can set `$data` correctly. – jasonhansel Aug 03 '14 at 05:17
  • $data needs to be an array, whose keys are the names of form fields (generally, the contents of the `name` attributes of `input` tags), and whose values are the contents of those fields. For instance, if the second form contains ``, $data should look like `array('User' => $userName)`, where $userName is the value that should go in the User field of the second form. – jasonhansel Aug 03 '14 at 05:24
  • If the second form is using `GET` to send its form data, you may be able to do this with just `file_get_contents`, as in `file_get_contents('http://othersite.com/form.php?User=username')`, but for `POST` you'll need to use cURL. – jasonhansel Aug 03 '14 at 05:25
  • yeah its post but so far i think i know what to do, doesnt seem overly hard. just its really late here already so im gonna sleep on it but once i get this live man, i honor my committments so keep abreast of changes on this post – user3147299 Aug 03 '14 at 05:33
  • No payment is necessary or expected :) – jasonhansel Aug 03 '14 at 05:34
  • people keep telling me that this is IMPOSSIBLE... :/ Am I missing something here? – user3147299 Aug 04 '14 at 15:03
-1

Depending on your need, the easier way to carry data to another page is through cookies. If you are using jQuery, you may look at this page to see how cookies work:

How do I set/unset cookie with jQuery?

Community
  • 1
  • 1
Joe H
  • 1,447
  • 2
  • 11
  • 8
  • http://www.the-art-of-web.com/javascript/setcookie/ that may actually work BUT i do not own form 2, only form 1... will that work? – user3147299 Aug 03 '14 at 05:14
  • Sorry, it wasn't clear in your original question that form 2 is outside of your control. You will need to know what the form 2 accepts as input, which could be HTTP GET, HTTP POST. Cookie is unlikely to work across servers. – Joe H Aug 03 '14 at 06:56