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

Link to comment
Share on other sites

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'] . '" />';

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Thanks But I thought if there was some better way out as In JSP we can forward the control to other page without browser being acknowledged about it,So I thought if PHP has some such sort of functionality

 

Thanks in advance

 

CSJakharia

Link to comment
Share on other sites

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.
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.