0

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

3

5 Answers 5

3

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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);
?>

1 Comment

But I dont want to send it in url, I want to POST the variables. because in a1.php its extract($_POST)
1

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

2 Comments

can I get hidden field values like this?
Yes, you can get the hidden field values in same way as you get text field values using javascript or jquery.
0

You can include a1.php inside a0.php so that all post variables are available in a1.php too

include('a1.php');

Comments

0

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!"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.