0

I am working on a web application where I need to send the value from one form to more than one page.

My form is simple :

<form method="post">
    <input type="text" name="name" value="">
    ...
</form>

I want the values from the form to be sent to :

  • 'page1.php' which will replace the actual page containing the form displaying the message : data saved
  • 'page2.php' which will open when I click the submit button to render the data as a PDF file

The problem is that I can only specify only one target using the action attribute of the form.

Anyone can helps ? Thanks in advance.

Could I use JavaScript or jQuery or other ?

manianis
  • 109
  • 3
  • 13
  • 1
    What do you exactly want to do ? When you submit your form, you want more than 1 page to open ? – Hearner Nov 02 '16 at 15:14
  • 1
    did you think about using `$_SESSION` variable to store form data?, the `$_SESSION` will be persistent within all your *.php pages – A l w a y s S u n n y Nov 02 '16 at 15:20
  • Can you clarify your idea @always sunny ? – manianis Nov 02 '16 at 19:13
  • @heaner, yes I want the values of the forms sent to two pages the first page is which that contains the form, the second one is not open until I submit the form than a new tab is created. – manianis Nov 02 '16 at 19:16

2 Answers2

1

You could use Jquery.post() with different URLs and the same data. More about the usage is here: https://api.jquery.com/jquery.post/

Lukas Kuhn
  • 86
  • 10
1

You can do it using JavaScript and jQuery for example. The easiest way is send two ajax requests:

$('form').submit(function() {
    $.ajax({
        async: false,
        method: 'POST',
        url: 'page2.php',
        data: $( this ).serialize(),
        success: function() {
             window.open("http://www.stackoverflow.com"); //this page will be open in new tab
        }
    });

    $.ajax({
        async: false,
        method: 'POST',
        url: 'page1.php',
        data: $( this ).serialize(),
        success: function() {
            window.location.href = "http://stackoverflow.com"; //redirect to this page
        }
    });
});