How do I get the value of a specific form from the previous page in PHP? [closed]

0

Good afternoon!

A page in PHP contains two form forms, each with a submit . How to get data from form 1, for example, after pressing submit through POST? Normally when there was only one form it would get the data directly through the code below: (where CNPJ was the id of a input of the form):

table {
  float: left;
}
<form id="localizacao" name="localizacao" method="post" action="rastreamento.php" onsubmit=" return false;">
  <table width="50%" border="1">
    <tr>
      <div align="center"><img src=img/logo.jpg></div>
    </tr>
    <tr>
      <th colspan="5" align="center" valign="top">
        <h2>Pesquisa</h2>
      </th>
    </tr>
    <tr>
      <td width="156">Selecione o STATUS:</td>
      <td>
        <select name="status" id="status">
          <option value="0">Recebido</option>
          <option value="1">Em trânsito</option>
          <option value="2">Encerrado</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>CNPJ:</td>
      <td width="835"><input name="CNPJ" type="text" id="CNPJ" size="20" maxlength="14" />
        <span class="style1">*</span> <span class="style3">somente n&uacute;meros</span></td>
    </tr>
    <tr>
      <td>
        VIAGEM:
      </td>
      <td width="835"><input name="VIAGEM" type="text" id="VIAGEM" size="20" maxlength="14" />
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <p>
          <input name="pesquisar" type="submit" id="pesquisar" value="Pesquisar" />
          <br />
          <input name="limpar" type="reset" id="limpar" value="Limpar!" />
          <br />
        </p>
      </td>
    </tr>
  </table>
</form>
<form id="alteracoes" name="alteracoes" method="post" action="rastreamento.php" onsubmit="return validaCampoAltera(); return false;">
  <table width="50%" border="1">
    <tr>
      <th colspan="5" align="center" valign="top">
        <h2>Modifica</h2>
      </th>
    </tr>
    <tr>
      <td width="50">VIAGEM:</td>
      <td width="835"><input name="VIAGEM" type="text" id="VIAGEM" size="20" maxlength="14" />
    </tr>
    <tr>
      <td width="50">NOVO STATUS:</td>
      <td width="835"><input name="NVSTATUS" type="text" id="NVSTATUS" size="1" maxlength="1" />
    </tr>
    <tr>
      <td width="50">EMBARCACAO:</td>
      <td width="835"><input name="EMBARC" type="text" id="EMBARC" size="20" maxlength="10" />
    </tr>
    <tr>
      <td width="50">DATA SAIDA:</td>
      <td width="835"><input name="DATSAI" type="text" id="DATSAI" size="20" maxlength="10" />
    </tr>
    <tr>
      <td width="50">HORA SAIDA:</td>
      <td width="835"><input name="HORSAI" type="text" id="HORSAI" size="20" maxlength="10" />
    </tr>
    <tr>
      <td width="50">DATA CHEGADA:</td>
      <td width="835"><input name="DATCH" type="text" id="DATCH" size="20" maxlength="10" />
    </tr>
    <tr>
      <td width="50">HORA CHEGADA:</td>
      <td width="835"><input name="HORCHE" type="text" id="HORCHE" size="20" maxlength="10" />
    </tr>
    <tr>
      <td colspan="2">
        <p>
          <input name="atualizar" type="submit" id="atualizar" value="ATUALIZAR" />
          <br />
        </p>
      </td>
    </tr>
  </table>
</form>

if (isset($_POST["CNPJ"])){ $CNPJ = $_POST ["CNPJ"]; }

    
asked by anonymous 11.07.2018 / 20:48

2 answers

0

The solution was to take the space that was in onsubmit and put true .

onsubmit=" return false;"

for

onsubmit="return true;"

in

<form id="localizacao" name="localizacao" method="post" action="rastreamento.php" onsubmit="return true;">
    
12.07.2018 / 19:46
0

Each page form, no matter how many, is submitted individually. So, if you have two forms and each one has its submit, only the form in which the submit was triggered will have the data sent to the server, remembering that each form should have its submit. In your case, if you click on the submit form "location", only its inputs will be sent via post, even if there are inputs in the other form with the same name. This should also be handled in your back end, since both forms send to the same file, your code should know how to compare, filter and handle the data capture according to the source form of the same.

    
12.07.2018 / 16:36