Jump to content


Photo

passing vareabls in links?


  • Please log in to reply
2 replies to this topic

#1 knowram

knowram
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 07 July 2006 - 03:42 AM

I am trying to create a back button on a form. would like to be able to send the variable $_REQUSET to the page that I am going back to. However I don't know what is used in that array to divide variables. so when I try to print it on the page that I am going back to all i get is  "ARRAY". here is the code that I am using
the like is:
<a href="diagnoses.php?backinfo=<?=$_REQUEST?>">Back To Diagnoses</a>
diagnoses.php being the previous page that I am trying to go back to.
and the cod for on the diagnoses.php page to see if the info has been submitted and I can get to it is:
echo'<pre>';
print_r ($backinfo);
echo '</pre>';
I have been able to submit arrays through links like this before but they have always been arrays that I have made so I have known how to split them up on the following page.

dose this make any sense? If so have any ideas?

#2 CheesierAngel

CheesierAngel
  • Members
  • PipPipPip
  • Advanced Member
  • 105 posts
  • LocationBelgium

Posted 07 July 2006 - 07:58 AM

The $_REQUEST var is an array of all $_GET and $_POST and $_SESSION variables.
The good way to pass all this vars from the array is to seperate them and putting
them into the $_POST array

<?php
foreach($_REQUEST as $key => $val) {
   $_POST[$key] = $val;
}
?>

<a href="diagnoses.php">Back To Diagnoses</a>

Or you could pass them by $_GET aswell
<?php
$var_get = "?";
foreach($_REQUEST as $key => $val) {
  if($var_get != "?") {
    $var_get .= "&";
  }
  $var_get .= "$key=$val";
}
?>

<a href='diagnoses.php<?php echo "$var_get"; ?>'>Back To Diagnoses</a>

Then on the next (or previous) page you can simply catch them again by the var $_REQUEST.

#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 07 July 2006 - 10:30 AM

You could serialize the array, put it in the link and then unserialize at the other page.

Example:
<?php
$data = serialize($_REQUEST);
echo "<a href='what-ever-page.php?data={$data}'>Back</a>";
?>
(If you'd like to use POST or GET instead of REQUEST you just replace it)

Another solution would be to use http_build_query to build a query string automaticly for you. You need to use PHP5 though.
Example:
<?php
$data = http_build_query($_REQUEST);
echo "<a href='what-ever-page.php?{$data}'>Back</a>";
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users