Hidden input fields of html do not come out in $_POST

Asked

Viewed 562 times

3

I have this 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 the 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 the 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 leave in the $_POST

Because?

The exit in the browser inspector is

Array
(
    [descricao] => teste
)
  • 1

    Already tried to define the property name theirs?

  • Work of chance? No! Work of tiredness! Thank you. If post as answer I accept it!

1 answer

5


Your fields Hidden do not own the property name definite:

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

Other than that, the quotation marks on value of the first field are not escaped, which may generate side effects in your application - or in the editor itself. Also, instead of <?php echo, you can use the simplified form <?=:

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

Difference between php <?php tags and <?=

In PHP what this <?= ? > tag represents?

  • value printing

  • @Carlosrocha I don’t understand your comment.

  • kkk, answer your question at the end of your answer: In PHP what does this <?= ? > tag represent?

  • @Carlosrocha but it was not a question, but a link to the question that deals with it :D

  • by default Short Tag set disabled

  • @Carlosrocha <?= it’s not a short tag, just <? is.

Show 1 more comment

Browser other questions tagged

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