Opening a new page and then executing header

-1

I currently have a button (print) that performs a submit on the form (since I need some fields that are in that form). This in turn executes the code that is in the action, where I have the following code:

echo "<script>window.open('".$url."', '_blank');</script>";

Well, if you run the script in this way, a new tab is opened in the browser, but the original page will fail (indexed variable that does not receive value). To get around this error, I thought about executing a header.

Looking like this:

header('location:../paginaOriginal.php');
echo "<script>window.open('".$url."', '_blank');</script>";
exit;

But when I put the header, it does not open the new tab, simply reload the page.

Button script:

    $("#botao1").click(function(){
        $("#form").submit();
});

Ideally the original page should remain static because it is a print button. But I need some fields that are in the form of that page and put that data in a layout already ready.

    
asked by anonymous 15.02.2015 / 14:44

1 answer

1

I believe you do not need PHP for this function. send your post to a new tab.

<form action="pagina.php" type="post" target="_blank">
<input name="test" value="1" />
<input type="submit" value="Submit">     
</form>

page.php

<?php
//seu código vai aqui
//--------------
//redirect se você realmente precisa disso
header('location:'.$url);
    
18.02.2015 / 03:14