Forum Moderators: open

Message Too Old, No Replies

sending a POST query along with a redirect

without pressing a button

         

sebbothebutcher

7:17 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



hi! i wanted to know if there is a way with javascript to send a POST variable to the page that the first one is refreshing to...
the redirect looks like this:

<meta http-equiv="refresh" content="0; URL=index2.php">

example:

index.php --refreshes to & sends POST var--> index2.php

thanks in advance!

Birdman

7:35 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think so. Can you just change the action attribute in the form to point to the correct file?

<form action="/index2.php"...

Since you are using PHP, there are other ways.

1) You could send all the POST params to the next page via GET, like so:

<?php
$url = "/index2.php?r=1";
foreach($_POST as $key => $val) $url .= "&".$key."=".$val;
header("Location: ".$url);
exit;
?>

You may need to alter the script to use the GET params, rather than POST. This depends on whether register_globals is on or off.

2) Use PHP to rebuild the form and then auto-submit with JavaScript:

<?php
$form = "";
foreach($_POST as $key => $val){
$form .= "<input type=\"hidden\" name=\"".$key."\" value=\"".$val."\">";
}
?>
<html>
<head>
<script type="text/javascript">
window.onload = document.forms[0].submit();
</script>
</head>
<body>
<form action="/index2.php" method="post">
<?php print $form;?>
</form>
</body>
</html>