Temporarily store input data for a multicita response

0

How do I do it so that when I click the Reply button instead of taking me directly to the reply.php page, I temporarily store the data so I can quote more than one response by clicking on the reply button of different comments and taking me finally to the page reply.php where I can play with that data? With the code I have now I can only quote one person, I have no idea how to do it to quote more than one at a time.

<form action="../reply.php" method="POST">
   <input type="hidden" name="usuarioID" value="' . $u_id . '">
   <input type="hidden" name="mensaje" value="' . $mensaje . '">
   <button name="reply" type="submit">Responder</button>
</form>

reply.php

$usuario = mysqli_real_escape_string($connection, $_POST['usuarioID']);
$mensaje = mysqli_real_escape_string($connection, $_POST['mensaje']);

<form method="POST" action="' . replyComments($connection) . '">
<input type="hidden" name="usuario_respuesta" value="' . $_SESSION['u_id'] . '">
<input type="hidden" name="usuario" value="' . $usuario . '">
<input type="hidden" name="mensaje" value="' . $mensaje . '">
<textarea name="texto">
<span class="cita">De ' . $usuario . ': ' . $mensaje .'</span>
</textarea>
<button type="submit" name="submit">Enviar respuesta</button>
</form>

The function only makes it possible to collect the input and textarea data and register them in the database through an INSERT INTO.

    
asked by Kakotas7 23.01.2018 в 09:20
source

1 answer

2

It does not end up being clear what you are trying but I will try to give you an answer trying to get as close as possible to the solution you need.

To start you will need a array to save the answers , the answers will also be a array so you will be working with a two-dimensional array .

The array that saves the answers will be a session variable so that you do not lose the data every time you create a new answer.

We must save the answers when we give to submit, as you do not want to be taken directly to reply.php you will put in the action the same name of the page (then we will send it to reply.php ).

<form action="" method="POST">
<input type="hidden" name="usuarioID" value="' . $u_id . '">
<input type="hidden" name="mensaje" value="' . $mensaje . '">
<input type="submit" name="añadir" value="Añadir usuario">
<input type="submit" name="enviar" value="Enviar" formaction="../reply.php">

</form>
<?php

start_session();
if(!isset($_SESSION["resultados"])){
    $_SESSION["resultados"] = array();
}


if(isset[$_GET["añadir"]] || isset[$_GET["enviar"]]){
    if(isset[$_GET["usuarioID"]]){
        $usuarioID = $_GET["usuarioID"];
    }
    if(isset[$_GET["mensaje"]]){
        $mensaje = $_GET["mensaje"];
    }
}

$respuesta = array ($usuarioID,$mensaje);
array_push($_SESSION["resultados"], $respuesta);
?>

This way we save the answers in a session variable.

To show the contents of the array with making var_dumb() would suffice.

Note: I mention how it is shown, not how it is traversed, to walk you need for .

<?php
  var_dump($_SESSION["resultados"]);
?>

Note 2: There may be some error in the code since I have not had time to try it

    
answered by 23.01.2018 в 11:10