html input hidden fields do not exit in $ _POST

3

I have next jQuery

// JavaScript Document
$(document).ready(function() {


  $("#contato").on("submit", function () {

    var formData = new FormData(this); 

        $.ajax({
            url: "_requeridos/emailAcompanha.php",
            type: 'POST',
            data: formData,
            beforeSend: function() {            
               $("div.conversa div form div.contatoBaixo .btnAcesso").css('display', 'none');
               $("div.conversa div form div.contatoBaixo img").css('display', 'block');            
            },
            success: function (retorno) {

               $("div.conversa div form div.contatoBaixo .btnAcesso").css('display', 'block');
               $("div.conversa div form div.contatoBaixo img").css('display', 'none');

                if (retorno == "OK") {
                  resposta = "E-mail enviado com sucesso!";
                } else {
                  resposta = "Erro no envio do E-mail";
                }
               $(".resposta").css("display", "block");
               $(".resposta").html(resposta);    
               //refresh na página após 1 segundo
              // setTimeout(window.location.reload(),1000);

            },
            cache: false,
            contentType: false,
            processData: false
        });

    return false;

  }); 

});  

And form

<form id="contato"> 

   <input type="hidden" id="idEmail" value="<?php echo $_GET["idEmail"]; ?>" />
   <input type="hidden" id="adminCli" value="c" /> 

    <textarea placeholder="Descrição" class="textarea" name="descricao" id="descricao" cols="80" rows="15"></textarea><br /> <br /> 

    <div class="contatoBaixo"> 
       <img src="_img/_bannerImgs/spinner.gif" style="display:none;" />
       <input name="envia" class="btnAcesso" type="submit" value="Enviar" /> 
    </div>

 </form>       

And php

<?php

    require_once "../_controles/_conexao/Conexao.php";
    require_once "../_controles/_daos/EmailsDao.php";

    $connection = new Conexao(); 
    $conexao = $connection->abreConexao();

    $emailDao = new EmailsDao($conexao);

print "<pre>";
print_r($_POST);    
print "</pre>";


    $gravarResposta = $emailDao->responder($_POST["idEmail"], $_POST["descricao"], $_POST["adminCli"]);

    echo $gravarResposta ? "OK" : "ERRO";

?>

When printing:

print "<pre>";
print_r($_POST);    
print "</pre>";

The fields input hidden of html do not exit $_POST

Why?

The exit in browser inspector is

Array
(
    [descricao] => teste
)
    
asked by anonymous 01.06.2018 / 15:30

1 answer

5

Your hidden fields do not have the name property defined:

<input type="hidden" id="idEmail" value="<?php echo $_GET["idEmail"]; ?>" />
<input type="hidden" id="adminCli" value="c" /> 

Otherwise, the quotation marks in% with% of the first field are not escaped, which can cause side effects in your application - or in the publisher itself. Also, instead of value , you can use the simplified form <?php echo :

<input name="email" type="hidden" id="idEmail" value="<?= $_GET['idEmail'] ?>" />

Difference between php tags

01.06.2018 / 15:38