Passing $_POST through the URL

Asked

Viewed 1,158 times

0

  1. I have a form that is mounted dynamically according to the preferences of each user and is submitted via post to the page that does the process.

  2. In the process page I need, among other things, to load an iframe that will bring extra information, according to the dynamic form information of the first screen.

My problem is right there: how to pass the information to the iframe bring the extra information?

Example: Form

<form method="post" action="processa.php">

   <label>Ano</label>
   <div>
      <select id="ano" name="ano">
         <option value="0">2000</option>
         <option value="1">2001</option>
         <option value="2">2002</option>
      </select>                     
   </div>

   <label>Mes</label>
   <div>
      <input type="text" id="mes" name="mes">                     
   </div>

   <label>Dia</label>
   <div>
      <input type="text" id="dia" name="dia">                    
   </div>

</form>

Example: Page that processes

<?php
   $_SESSION["pesquisa"] = $_POST; //ERRO POIS $_POST RETORNA ARRAY
   $_SESSION["pesquisa"] = implode("&",$_POST); //NAO SERVE POIS FICA 2000&03&12
?>

<script>
   parent.iframe.location.href = 'mais_infos.php?<?php echo $_SESSION["pesquisa"];?>';
</script>

I would need mine $_SESSION["pesquisa"] something like ano=2000&mes=03&dia=12 to be able to complete the URL, but remembering again, the form fields are mounted dynamically.

  • 1

    You can try using, serialize (to store) and unserialize (to recover).

  • @Rafaelwithoeft with the serialize my post was something like a:6:{s:8:"indice_9";s:6:"DOC 01";s:9:"indice_10";s:4:"2015";s:9:"indice_11";s:2:"03";s:9:"indice_12";s:1:"1";s. I wouldn’t have any other choice?

  • And in the unserialize, Did you normally recover the value? Or do you need to be readable on Session?

  • 1

    Sorry, I had not seen that you wanted to pass the value in the url of iframe, you can also try using the following function: http_build_query. Example: http_build_query( ['parametro1' => '123', 'parametro2'=> '123'] ). And you can test by passing the post directly http_build_query($_POST);

  • @Rafaelwithoeft also worked with http_build_query, only detail is that this function exchanges spaces in the value of the fields by +.

1 answer

2


What I understand is you need to pass data from a form to iframe dynamically. As the data comes via POST, soon would come in format $_POST['nome_campo'] = valor. In case you make a

$variavel = '';
foreach ($arrayPost as $campo => $valor){
    if (end($arrayPost) != $valor)
        $variavel .= $campo.'='.$valor.'&';
    else
        $variavel .= $campo.'='.$valor;
}

Check if in variable $variavel return exactly what you want.

  • 2

    That’s right! Thanks man, very good. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.