Reputation: 183
I need form data to be sent to two different pages(a0.php & a1.php)
. I cant use session because I dont have access to (a1.php)
page.
So now i want some intermediate page where i can access the form data and redirect to another page as form post itself.
existing
//front end
<form action="a1.php" method="post">
</form>
//a1.php
<?php
var_dump($_POST);
?>
Needed
//front end
<form action="a0.php" method="post">
</form>
//a0.php
<?php
var_dump($_POST); //access form data here
header("location:a1.php")// pass form post data through redirection
?>
//a1.php
<?php
var_dump($_POST); //access form data here also in same format/fashion
?>
Note: I dont want to pass parameters in url, in this case, I prefer POST
over GET
Upvotes: 0
Views: 6039
Reputation: 1
It seems that in the days of jQuery, Angular Js and Ajax, people are forgetting about plain Javascript. Around 2005, I had submitted a php page to itself and to another php page in another Frame. Here is my code:
JS
function validate() {
var valid = true;
if(valid) {
document.f1.target = "headframe";
document.f1.action = "page1.php"; // This is the same page
document.f1.submit();
document.f1.target = "mainframe";
document.f1.action = "page2.php"; // Another page
document.f1.submit();
}
}
It still works perfectly. KISS principle says "Keep it simple, stupid!"
Upvotes: 0
Reputation: 813
Here you can use ajax.
When you will click submit button, then using jquery you can get the values and post to a page using ajax.
Then the first form will be submitted after the ajax call.
<script type="text/javascript">
function ajax_call_list()
{
var name = document.getElementById('name').value;
var address = document.getElementById('address').value;
var vURL = "b.php?name="+name+"&address="+address;
jQuery.ajax(
{
type: "POST", url: vURL, data: "", success: function(result)
{
if(result)
{
$("#form_submit").submit();
}
}
}
}
</script>
<form action="a.php" id="form_submit">
<input type="text" name="name" id="name">
<input type="address" name="address" id="address">
<input type="submit" name="submit" value="Submit" onClick="callAjax()">
</form>
I hope it will help.
Thanks
Upvotes: 1
Reputation: 1053
You can include a1.php inside a0.php so that all post variables are available in a1.php too
include('a1.php');
Upvotes: 0
Reputation: 1487
You can use javascript.
onClick
will fire function that will send the data to first page without refreshing (ajax), and so send to the second page.
<form>
<button type=submit" onclick="x()" >
</form>
<script>
function x(){
//ajax to a1.php
//send to a2.php
}
</script>
Upvotes: 3
Reputation: 870
Please try the following:
On a0.php page
<?php
$queryString = http_build_query($_REQUEST);
header("Location: a1.php?" . $queryString );
?>
On a1.php
<?php
var_dump($_REQUEST);
?>
Upvotes: 1