title: Send/Post Form Data to Url with PHP
body: <p>I have a form that submits via POST and I capture the variables once the form is submitted.</p>
  
  <p>How can I concatenate the form data and then POST it to the url then re-direct to the thank you page?</p>
  
  <p>This is not the exact code, I just can't find any normal answers, and I'm sure there is more than one way to do this. Just trying to figure out the simplest way possible.</p>
  
  <pre><code>if(isset($_POST['submit'])){
      $var1 = $_POST['var1'];
      $var2 = $_POST['var2'];
  
  $url = 'https://api.this.com/foo/bar?token=IHAVETOKEN&amp;foo=$Var1&amp;bar=$var2'
  
  post_request_to($url);
  
  header("Location: thankyou.php");
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>HERE IS THE ACTUAL ANSWER/WORKING CODE:</p>
  
  <pre><code>if(isset($_GET['submit'])){
    $firstName = $_GET['firstname'];
    $lastName = $_GET['lastname'];
    $email = $_GET['email'];
    $password = $_GET['password'];
    $phone = $_GET['phone'];
  }
  
    $data = array(
          'token' =&gt; 'sadfhjka;sdfhj;asdfjh;hadfshj',
          'firstName' =&gt; $firstName,
          'lastName' =&gt; $lastName,
          'email' =&gt; $email,
          'password' =&gt; $password,
          'phone' =&gt; $phone
  
      );
  
  
    $postvars = http_build_query($data) . "\n";
  
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.com/foo/bar?');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
    $server_output = curl_exec ($ch);
  
    curl_close ($ch);
  </code></pre>