-1

I am trying to pass variables from a form to a website page. Here is the guide that I am following: https://www.jotform.com/help/213-Send-POST-Data-From-JotForm-Using-PHP-in-Custom-Thank-You-Page

Here is the code on my redirect.php page:

   <?php
     $answers = $_POST;
      $url1 = "http://www.example.com/results";

      $var1 = "?user_email =".urlencode($answers[user_email]);
      $var2 = "&input_63 =".urlencode($answers[input_63]);
      $var3 = "&input_64 =".urlencode($answers[input_64]);
      $var4 = "&input_65 =".urlencode($answers[input_65]);
      $var5 = "&input_66 =".urlencode($answers[input_66]);
      $var6 = "&input_67 =".urlencode($answers[input_67]);
      $var7 = "&input_68 =".urlencode($answers[input_68]);
      $var8 = "&input_69 =".urlencode($answers[input_69]);
      $var9 = "&input_70 =".urlencode($answers[input_71]);
      $var10 = "&input_71 =".urlencode($answers[input_71]);
      $var11 = "&input_55 =".urlencode($answers[input_55]);
      $var12 = "&input_56 =".urlencode($answers[input_56]);
      $var13 = "&input_57 =".urlencode($answers[input_57]);
      $url2=$url1.$var1.$var2.$var3.$var4.$var5.$var6.$var7.$var8.$var9.$var10.$var11.$var12.$var13;
      header("location:$url2");
    ?>

The variables show up on the page as ' '.

I have no clue what to do and help would be greatly appreciated.

3 Answers3

1

If you are able to change the input names into an array then it is much simpler. If not, then you can pass the data several ways. Using a session:

session_start();
$_SESSION['answers'] = $_POST;
header("location: $url1");

Then on the next page:

session_start();
$answers = $_SESSION['answers'];
echo $answers['user_email'];

I wouldn't do it, but if you insist on the URL method, then this is far easier:

$query = http_build_query($_POST);
header("location: $url1?$query");

http_build_query() will URL encode and build the string.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
  • I'm sure hoping your answer will solve what they're trying to do. Seeing their other similar post http://stackoverflow.com/q/39772219/ the OP states the following: *"It is currently displaying the variable as `' '`"*. I'm wondering if that won't be the case for that question also and "how" they're using that file, as I stated in comments under the other question, being [this comment](http://stackoverflow.com/questions/39772219/redirecting-php-variables-to-new-webpage-use#comment66839030_39772219). – Funk Forty Niner Sep 30 '16 at 23:20
0

TO pass variables from a form to a php page in php is rather simple

First your form

<form method="POST" action="page_to_send_data_to.php">
  <input type="" name="something" value=""></input>
  <input type="" name="somethingelse" value=""></input>
  <input type="submit"></input>
</form>

Then on the page you submit to

<?php 
if(!isset($_POST['something']) {
    $var1 = $_POST['something'];
    $var2 = $_POST['something'];
}
echo $var1.' '.$var2;
?>
Bruce
  • 1,039
  • 1
  • 9
  • 31
  • I offered this as an answer because I can't possibly see the need to submit something as a POST and build a custom url string from it, you could just as easily use a GET instead of a POST and cut out the redirect. Also I don't really see the purpose is storing the data in a session either. Nor do I see any logic in building an array from the data. I suppose without seeing the forms and what they are doing, is a bit of a guessing game, but if they are basic forms, I highly recommend this solution. – Bruce Sep 30 '16 at 22:24
0

Your url is probably corrupted because of spaces, you don't set input_63 to anything because you end with a space, you set input_63_ (with an underscore, spaces are converted to underscore by php's parsing logic), which i bet isn't what you're looking for in the following script. and stop making your queries manually, for the vast majority of cases, you should use http_build_query instead. like

$url2=$url1.'?'.http_build_query(array('input63'=>$answers[input_63],'input_64'=>$answers[input_64]))

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
hanshenrik
  • 19,904
  • 4
  • 43
  • 89