Pass PHP variable onclick="history.go (-1)"

0

I'm trying to create a button that returns the form to correct it, thus keeping all content typed in HTML for the user to correct the wrong information, however sending a PHP variable so I can do the UPDATE in MySQL without inserting a new one. I thought about sending ID :

<!DOCTYPE html>          
<html>
<body>
    <form>
        <input type="hidden" name="ID" value="<?php echo $ID; ?>"/>
        <input type="submit" formaction="cancela_cadastro.php" 
               value="Cancelar pedido">
        <input type="submit" formaction="../index.php" value="novo pedido">
        <input type="button" value="Corrigir" 
            onClick="(history.go(-1), '<?php echo $ID; ?>')"/>
    </form>

but without success. The ID is inserted in "cancela_cadastro.php?ID=XX" and "../index.php?ID=XX" - the latter unintentionally, but it makes no difference. I would like to know if there is a way to send this variable in history.go(-1) , or if there is a way to send this variable on return to the completed form.

PS . The history.go(-1) stopped working when I assigned this PHP variable.

    
asked by anonymous 07.12.2017 / 20:08

2 answers

0

Instead of doing history.go(-1) create a function where you pass the ID and redirect it to the page you need for example:

<script>
function redirect(id){

    window.location.href = 'suapagina.php?id='+id;

}
</script>

If you want to add the page parameter in the method, you can reuse it elsewhere if necessary.

    
07.12.2017 / 20:15
1

Instead of:

<input type="button" value="Corrigir" onClick="(history.go(-1), '<?php echo $ID; ?>')">

I suggest:

<input type="button" value="Corrigir" onClick="parent.location.href='pagina_destino.php?id=<?php echo $ID; ?>'">
    
07.12.2017 / 20:25