Skip to main content
May 27, 2010
Answered

Passing values via $insertGoTo?

  • May 27, 2010
  • 1 reply
  • 2387 views

Hello all,

I am using the canonical Dreamweaver/PHP construct to direct to another php page upon submit.

$insertGoTo = "confirm_submission.php";
if (isset($_SERVER['QUERY_STRING'])) {
  $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  $insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));

Is it possible to pass additional values to the "confirm_submission.php" page?  I know how to do this using a regular URL GET method.  Doing so with the above construct is a bit less clear.

I neglected to mention that these are form variables that I am interested in passing.

Thanks!

Message was edited by: ByteSmythe (added clarity regarding form variables)

This topic has been closed for replies.
Correct answer bregent

>You probably don't need to test if the querystring exist for anything except the first value. That will streamline things quite a bit.

Good point.  You're saying simply concatenate the remainder onto $insertGoTo?

Also, I have one value that I want to pass hidden.  What is the best way to do that?  As a form value?  Sorry if this is an FAQ.  I am a long time HTML/CGI programmer and new to PHP via Dreamweaver.


Yeah. Use the if/else to check and append the first value but after that it's safe to assume that the querystring exists so just concatenate the other key/values pairs.

>Also, I have one value that I want to pass hidden.

I'd probably use a session variable for that.

1 reply

May 27, 2010

I found an old post by David that suggests

  // if a query string has been added, add the value at the end
  // otherwise, create a query string to add value
  if (strpos($insertGoTo, '?')) {
   $insertGoTo .= '&rep_fname=' . $_POST['RepFname'];
  } else {
   $insertGoTo .= '?rep_fname=' . $_POST['RepFname'];
  }

  header(sprintf("Location: %s", $insertGoTo));

Which appears to work when I access the variable via $_GET['rep_fname'] in the php file to which the user is redirected.  It seems a pity to have to do this for 10 variables but I suspect this is cleaner than using something a global session variable ($_SESSION).

Participating Frequently
May 27, 2010

>It seems a pity to have to do this for 10 variables

You probably don't need to test if the querystring exist for anything except the first value. That will streamline things quite a bit.

bregentCorrect answer
Participating Frequently
May 28, 2010

>You probably don't need to test if the querystring exist for anything except the first value. That will streamline things quite a bit.

Good point.  You're saying simply concatenate the remainder onto $insertGoTo?

Also, I have one value that I want to pass hidden.  What is the best way to do that?  As a form value?  Sorry if this is an FAQ.  I am a long time HTML/CGI programmer and new to PHP via Dreamweaver.


Yeah. Use the if/else to check and append the first value but after that it's safe to assume that the querystring exists so just concatenate the other key/values pairs.

>Also, I have one value that I want to pass hidden.

I'd probably use a session variable for that.