Jump to content

Forward to page alongwith Variables in POST


csplrj

Recommended Posts

How to forward a page to another page alongwith the parameters passed into it

 

I mean I have page a.php

which is called with some parameters in $_POST and I require to pass these to another page with same variables in $_POST

 

Please Help for the same

 

Thanks in advance

 

CSJakharia

just use a form with the post attribute. set all of the $_POST variables as hidden inputs with the same name as the $_POST[].

 

something like:

echo '<input type="hidden" name="NAME OF VARIABLE HERE" value="' . $_POST['NAME OF VARIABLE HERE'] . '" />';

a.php (this file has already received some post variables)

 

<?php

echo "<form action=\"b.php\" method=\"post\">\n";

foreach($_POST as $k => $v) {
echo " <input type=\"hidden\" name=\"$k\" value=\"$v\" />\n";
}

// Output the rest of your form here

?>

No The whole scenorio is

 

ab.html has all the elements

 

it has form tag with action to a.php

 

a.php later requires to forward the variables in the $_POST to b.php as POST only

 

I hope now you got my question

 

i do not require to show another form in a.php but it will forward the controls to b.php

 

Thanks in advance

 

CSJakharia

You want sessions man 

 

www.php.net/session

www.php.net/session_start

 

Remember that session_start(); has to be at the top of a.php and b.php before ANY output is sent to the screen.

 

a.php

<?php
session_start();

// register post as session vars
foreach ($_POST as $key => $val) {
       $_SESSION[$key] = $val;
}

// goto b.php somehow
echo '<a href=b.php>Goto B.php</a>';
?>

 

 

b.php

<?php
session_start();

// viola the variables are passed to b.php without the user ever knowing.
echo '<pre>',print_r($_SESSION),'</pre>'; // thanks to chigley for pointing out that mistake.
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.