How to rescue large amount of variables sent by POST and use them?

Asked

Viewed 89 times

0

I have a problem rescuing large amount of variables sent by the method $_POST. I was using this code earlier:

import_request_variables("gp", "rvar_");

But the same was discontinued and my script stopped working, I tried to do through a loop, but I did not succeed in trying to use it, I did so:

foreach( $_POST as $NomeCampo => $Variavel)
{ 
   $VarNome = "$" . $NomeCampo . "='" . $Variavel . "';"; 
   eval($VarNome); 
} 

Form Code:

  <form name="form1" method="post" action="containerFormulario.php?conteudo=instrucao/rh_forms/AutorizaoContratacaoImpre.php">
  <table width="85%" border="0" align="center" cellspacing="3" class="corpoTabela">
     <tr>
        <td height="21" class="tituloTabela">
           <div align="center">Autoriza&ccedil;&atilde;o para Contrata&ccedil;&atilde;o de Pessoal </div>
        </td>
     </tr>
     <tr>
        <td>
           <div align="center">
              <table width="100%"  border="0">
                 <tr>
                    <td colspan="4">&nbsp;</td>
                 </tr>
                 <tr>
                    <td width="7%">&nbsp;</td>
                    <td width="28%" class="corpoDocumento"><strong>Unidade Requisitante</strong> </td>
                    <td width="65" colspan="2" class="corpoDocumento">
                       <select name="Unidade" id="Unidade">
                          <?php
                             do {  
                             ?>
                          <option value="<?php echo $row_rcs_unidades['IdUnicoop']?>"><?php echo $row_rcs_unidades['Nome']?></option>
                          <?php
                             } while ($row_rcs_unidades = mysql_fetch_assoc($rcs_unidades));
                                 $rows = mysql_num_rows($rcs_unidades);
                             if($rows > 0) {
                                 mysql_data_seek($rcs_unidades, 0);
                                 $row_rcs_unidades = mysql_fetch_assoc($rcs_unidades);
                             }
                             ?>
                       </select>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Nome do Candidato</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <input name='Candidato' type=text id="Candidato"  size=50>
                       </font>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Endere&ccedil;o Residencial</strong> </td>
                    <td class="corpoDocumento">
                       <input name='Endereco' type=text id="Endereco"  size=50>
                       </font>
                    </td>
                    <td class="corpoDocumento">&nbsp;</td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Bairro</strong></td>
                    <td colspan="2" class="corpoDocumento"><input name='Bairro' type=text id="Bairro"  size=50></td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Telefone</strong></td>
                    <td colspan="2" class="corpoDocumento"><input name='Telefone' type=text id="Telefone"  size=50></td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Cargo</strong></td>
                    <td colspan="2" class="corpoDocumento"><input name='Cargo' type=text id="Cargo"  size=50></td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Se&ccedil;&atilde;o</strong></td>
                    <td colspan="2" class="corpoDocumento"><input name='Sessao' type=text id="Sessao"  size=50></td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Subse&ccedil;&atilde;o</strong></td>
                    <td colspan="2" class="corpoDocumento"><input name='Subsecao' type=text id="Subsecao"  size=50></td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Sal&aacute;rio Inicial</strong></td>
                    <td colspan="2" class="corpoDocumento"><input name='SalarioInicial' type=text id="salarioIncial" size=8 maxlength="10" onBlur="soma()">
                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Código </strong>
                       <input name='CodigoInicial' type=text id="codigoIncial" size=8 maxlength="10">              
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Sal&aacute;rio Após 90 dias</strong></td>
                    <td colspan="2" class="corpoDocumento"><input name='SalarioApos' type=text id="SalarioApos" size=8 maxlength="10" onBlur="soma()">
                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Código</strong>
                       <input name='CodigoFinal' type=text id="CodigoFinal" size=8 maxlength="10">
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>%</strong></td>
                    <td colspan="2" class="corpoDocumento"><input name='Calculo' type=text id="Calculo" onFocus="soma()" onBlur="valida()" size="8" maxlength="10" readonly>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Data de Admiss&atilde;o</strong> </td>
                    <td colspan="2" class="corpoDocumento"><font size="2" face="Tahoma">
                       <input name="Data" type="text" id="Data" onKeyUp="formataData(this)" size="10" maxlength="10">
                       </font>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Contrato Experi&ecirc;ncia - Dias</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <input name='Contrato' type=text id="Contrato"  size=3>
                       </font>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Hor&aacute;rio de trabalho</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <input name='Horario' type=text  id="carga2" size=35>
                       </font><strong> C&oacute;digo </strong>
                       <input name='CodigoHorarioTrabalho' type=text id="codigoIncial2" size=8 maxlength="10">
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Jornada de Trabalho</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <table width="439" class="corpoDocumento">
                          <tr>
                             <td><label>
                                <input name="Opcoes" type="radio" value="Turno 12 x 36" checked>
                                Turno 12 x 36</label>
                             </td>
                          </tr>
                          <tr>
                             <td><label>
                                <input type="radio" name="Opcoes" value="Banco de Horas at&eacute; 19:00 - proibido trabalhar de S&aacute;bado">
                                Banco de Horas at&eacute; 19:00 - proibido trabalhar de S&aacute;bado</label>
                             </td>
                          </tr>
                          <tr>
                             <td><label>
                                <input type="radio" name="Opcoes" value="Horas Extras - hor&aacute;rio operacional - S&aacute;bado">
                                Horas Extras - hor&aacute;rio operacional - S&aacute;bado</label>
                             </td>
                          </tr>
                          <tr>
                             <td><label>
                                <input type="radio" name="opcoes" value="Compensa&ccedil;&atilde;o de Jornada - proibido trabalhar de S&aacute;bado">
                                Compensa&ccedil;&atilde;o de Jornada - proibido trabalhar de S&aacute;bado</label>
                             </td>
                          </tr>
                          <tr>
                             <td><label>
                                <input type="radio" name="opcoes" value="Outros Hor&aacute;rios">
                                Outros Hor&aacute;rios
                                <input name="OutrosHorarios" type="text" id="OutrosHorarios">
                                </label>
                             </td>
                          </tr>
                       </table>
                    </td>
                 </tr>
                 <tr>
                    <td>
                       <div align="center"></div>
                    </td>
                    <td class="corpoDocumento"><strong>Grau de Instru&ccedil;&atilde;o</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <select name="Instrucao" size="1" id="Instrucao">
                          <option>Grau de Instru&ccedil;&atilde;o - Selecione</option>
                          <option value="Prim&aacute;rio">Prim&aacute;rio</option>
                          <option value="Prim&aacute;rio - Incompleto">Prim&aacute;rio - Incompleto</option>
                          <option value="Primeiro Grau">Primeiro Grau</option>
                          <option value="Primeiro Grau - Incompleto">Primeiro Grau - Incompleto</option>
                          <option value="Segundo Grau">Segundo Grau</option>
                          <option value="Segundo Grau - Incompleto">Segundo Grau - Incompleto</option>
                          <option value="Terceiro Grau">Terceiro Grau</option>
                          <option value="Terceiro Grau - Incompleto">Terceiro Grau - Incompleto</option>
                          <option value="P&oacute;s-Gradua&ccedil;&atilde;o">P&oacute;s-Gradua&ccedil;&atilde;o</option>
                          <option value="P&oacute;s-Gradua&ccedil;&atilde;o Incompleta">P&oacute;s-Gradua&ccedil;&atilde;o Incompleta</option>
                       </select>
                       </span>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Estado Civil</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <select name="EstadoCivil" size="1" id="EstadoCivil">
                          <option>Estado Civil - Selecione</option>
                          <option value="Solteiro">Solteiro</option>
                          <option value="Casado">Casado</option>
                          <option value="Vi&uacute;vo">Vi&uacute;vo</option>
                          <option value="Separado">Separado</option>
                          <option value="Outros">Outros</option>
                       </select>
                       </span>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Idade</strong></td>
                    <td colspan="2" class="corpoDocumento">
                       <input name="Idade" type="text" id="Idade" size="19">
                       </span>
                    </td>
                 </tr>
                 <!-- <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento">Tempo de Resid&ecirc;ncia </td>
                    <td class="corpoDocumento">
                      <input name="Residencia" type="text" id="Residencia" size="19">
                    </span></td>
                    </tr>-->
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Trabalhou anteriormente na Cocari</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <table width="100%" border="0">
                          <tr>
                             <td class="corpoDocumento"><input name="Trabalhou" type="radio" id="radio" onClick="visivel5('1')" value="Sim" checked="checked" />
                                Sim, informar local
                                <input name="Trabalhou" type="radio" id="radio2" onClick="visivel5('0')" value="N&atilde;o" />
                                N&atilde;o
                                &nbsp;                    <input name="Local" type="text"  id="Local" class="corpoDocumento" size="30" maxlength="30" />                  
                             </td>
                          </tr>
                       </table>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Em que per&iacute;odo?</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <input name="Periodo" type="text" id="Periodo" size="19">
                       </span>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Em que fun&ccedil;&atilde;o?</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <input name="Funcao" type="text" id="Funcao" size="47">
                       </span>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Motivo da Sa&iacute;da</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <input name="Saida" type="text" id="Saida" size="47">
                       </span>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Especificar Motivo</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <table width="275" class="corpoDocumento">
                          <tr>
                             <td width="267"><label>
                                <input name="Motivo" type="radio" value="Contratação" checked>
                                Contratação</label>
                             </td>
                          </tr>
                          <tr>
                             <td><label>
                                <input type="radio" name="Motivo" value="Recontratação">
                                Recontratação</label>
                             </td>
                          </tr>
                          <tr>
                             <td><label>
                                <input type="radio" name="Motivo" value="Substituição">
                                Substituição</label>
                             </td>
                          </tr>
                          <tr>
                             <td><label>
                                <input type="radio" name="Motivo" value="Safra (Employer)">
                                Safra (Employer)</label>
                             </td>
                          </tr>
                          <tr>
                             <td><label>
                                <input type="radio" name="Motivo" value="Rotatividade">
                                Rotatividade</label>
                             </td>
                          </tr>
                       </table>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Nome do Substituto</strong> </td>
                    <td colspan="2" class="corpoDocumento">
                       <input name="Substituto" type="text" id="Substituto" size="47">
                       </span>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento"><strong>Observa&ccedil;&otilde;es</strong></td>
                    <td colspan="2" class="corpoDocumento"><textarea name="Observacao" cols="70" rows="5" id="Observacao"></textarea></td>
                 </tr>
                 <tr>
                    <td colspan="4">&nbsp;</td>
                 </tr>
                 <tr>
                    <td colspan="4" align="center">
                       <select name="dia" class="style1" id="dia">
                          <option selected="selected">1</option>
                          <option>2</option>
                          <option>3</option>
                          <option>4</option>
                          <option>5</option>
                          <option>6</option>
                          <option>7</option>
                          <option>8</option>
                          <option>9</option>
                          <option>10</option>
                          <option>11</option>
                          <option>12</option>
                          <option>13</option>
                          <option>14</option>
                          <option>15</option>
                          <option>16</option>
                          <option>17</option>
                          <option>18</option>
                          <option>19</option>
                          <option>20</option>
                          <option>21</option>
                          <option>22</option>
                          <option>23</option>
                          <option>24</option>
                          <option>25</option>
                          <option>26</option>
                          <option>27</option>
                          <option>28</option>
                          <option>29</option>
                          <option>30</option>
                          <option>31</option>
                       </select>
                       <select name="mes" class="style1" id="mes">
                          <option>Janeiro</option>
                          <option>Fevereiro</option>
                          <option>Mar&ccedil;o</option>
                          <option>Abril</option>
                          <option>Maio</option>
                          <option>Junho</option>
                          <option>Julho</option>
                          <option>Agosto</option>
                          <option>Setembro</option>
                          <option>Outubro</option>
                          <option>Novembro</option>
                          <option>Dezembro</option>
                       </select>
                       <font face="Tahoma">
                          <select name="ano" class="style1" id="ano">
                             <option>
                                <?php setlocale(LC_TIME,"portuguese"); echo strftime("%Y"); ?>
                             </option>
                          </select>
                       </font>
                    </td>
                 </tr>
                 <tr>
                    <td colspan="4">&nbsp;</td>
                 </tr>
                 <tr>
                    <td colspan="4">
                       <div align="center" class="corpoDocumento">Gerente
                          da Unidade&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          Gerente Recursos
                          Humanos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          Superintendente</span>
                       </div>
                    </td>
                 </tr>
                 <tr>
                    <td>&nbsp;</td>
                    <td class="corpoDocumento">&nbsp;</td>
                    <td colspan="2" class="corpoDocumento">&nbsp;</td>
                 </tr>
              </table>
           </div>
        </td>
     </tr>
  </table>
  <p align="center">
     <input type="submit" name="Submit" value="Preparar Impress&atilde;o" onClick="valida()">
  </p>

Because the above result is not bringing me all the values reported on the form?

  • How many fields your POST has?

  • Hello @Kayobruno, approximately 30 fields.

  • Strange PHP has max_input_vars but this quantity ai is still very far from the maximum, check if all inputs are with the name set.

  • There’s a way to put in the form code for us to analyze?

  • Insert the form code @Ademirmazerjr-Nuno.

  • How did you identify that not all values are coming? You executed var_demp($_POST)? If yes, what was the result? If not, execute it.

  • var_dump is bringing all fields reported in the form @Andersoncarloswoss.

  • Already tried using the function extract? She basically does what her foreach should do.

  • When I check the $Varnome variable it only brings me the last form field, there’s my difficulty.

  • Could you put an example of what it would look like @Andersoncarloswoss?

  • 1

    extract($_POST), the keys will define the variable names and therefore all valid names should be.

Show 6 more comments

2 answers

1

I needed a business like this yesterday:

<form action='eumesmo.php' method='post'>
<input type='text' name='a'>
<input type='text' name='b'>

<input type='SUBMIT' VALUE='ENVIAR'>

</form>

<?php

foreach ($_POST as $key => $valor) {
    //Defina $var pelo $key
    echo $key;
    $var = "$".$key;
    //Nomeia a var com o nome, e insere valor do _POST relacionado.
    $$var = $_POST[$key];
    //Escreve o valor do post;
    echo $$var;
}

1


I managed to solve in a simple way, following a tip from Anderson Carlos Woss the code was like this:

Extract($_POST, EXTR_PREFIX_SAME, "c");

The above code, if there is a variable with the same name, adds a prefix to the variable name defined by the prefix argument.

Browser other questions tagged

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