0

When the form is submitted I get a error Notice: Undefined index: inputValorFrete in /home/... Because I try to access an array key inputValorFrete.

<form id="formcomprar" name="formcomprar" method="post" action="pedido-realizado.php">
<input type="hidden" name="inputValorFrete" id="inputValorFrete" value="15.90" />
...
</form>

So, using var_dump($_POST["inputValorFrete"]) I getting the key inputValorFrete correctly.

string(5) "15.90"

You can see the initialized key when access var_dump($_POST) to.

["inputValorFrete"]=>string(5) "15.90"

My question is: Why the error happens when I access $_POST["inputValorFrete"], however when I using var_dump this show the array with the correct key?

Complete var_dump($_POST):

 array(46) {
  ["cep"]=>
  string(8) "75240000"
  ["logradouro"]=>
  string(16) "Rua x QD x LT xx"
  ["complemento"]=>
  string(15) "Sem complemento"
  ["numero"]=>
  string(1) "0"
  ["bairro"]=>
  string(11) "Maria Nadir"
  ["cidade"]=>
  string(20) "xxx xxx xx"
  ["estado"]=>
  string(2) "xx"
  ["updatecliente"]=>
  string(1) "0"
  ["inputValorTotal"]=>
  string(6) "705.90"
  ["inputValorFrete"]=>
  string(5) "15.90"
  ["tipoFreteSelec"]=>
  string(5) "SEDEX"
  ["inputSubTotal"]=>
  string(6) "690.00"
  ["pesoproduto"]=>
  string(3) "500"
  ["hashcomprador"]=>
  string(64) "e5eaaf020b1455bec5702ea5ee4e0c6fbce26bf599aee59c943d11c256f87c8b"
  ["numerocartao"]=>
  string(0) ""
  ["cvvcartao"]=>
  string(0) ""
  ["mescartao"]=>
  string(0) ""
  ["anocartao"]=>
  string(0) ""
  ["nomecartao"]=>
  string(0) ""
  ["cpftitularcartao"]=>
  string(0) ""
  ["datanascimentotitularcartao"]=>
  string(0) ""
  ["telefonetitularcartao"]=>
  string(0) ""
  ["cependcartao"]=>
  string(0) ""
  ["logradouroendcartao"]=>
  string(0) ""
  ["numeroendcartao"]=>
  string(0) ""
  ["complementoendcartao"]=>
  string(0) ""
  ["bairroendcartao"]=>
  string(0) ""
  ["cidadeendcartao"]=>
  string(0) ""
  ["estadoendcartao"]=>
  string(0) ""
  ["paisendcartao"]=>
  string(6) "Brasil"
  ["opcaopagamento"]=>
  string(6) "boleto"
  ["installmentValue"]=>
  string(0) ""
  ["creditCardToken"]=>
  string(0) ""
  ["creditCardBrand"]=>
  string(0) ""
  ["tipoPagamento"]=>
  string(6) "BOLETO"
  ["nome"]=>
  string(25) "xxxx xx xxx"
  ["email"]=>
  string(21) "xxxxs@gmail.com"
  ["ddd"]=>
  string(2) "xx"
  ["telefone"]=>
  string(8) "xxxxxxxx"
  ["tipodoc"]=>
  string(3) "CPF"
  ["cpf"]=>
  string(11) "xxxxxxxxxx"
  ["fone"]=>
  string(10) "xxxxxxxxxx"
  ["fone1"]=>
  string(0) ""
  ["equipe"]=>
  string(0) ""
  ["pais"]=>
  string(3) "BRA"
  ["finalizar"]=>
  string(0) ""
}

part of the php code that receives the $ POST:

    if (isset($_POST)) {
        extract($_POST);

        //var_dump($_POST);
        //exit;

        //dividindo o valor do frete entre os produtos
        $valorFrete = $_POST["inputValorFrete"] / $quantItem;
...
Diogo Rodrigues
  • 1,312
  • 15
  • 15
  • 1
    What are you using `extract($_POST)` for here, if you access parameters using `$_POST` later on anyway? – CBroe Jul 07 '15 at 04:19
  • Would that not become `$inputValorFrete` because of the `extract()`? you wouldn't even need to set it. Remove the extract and set the values you need to manually. – Bankzilla Jul 07 '15 at 04:48
  • sorry for my inattention but the error occurs because I was redirecting to the same page of the post. Ex: location.href"pedido-realizado.php ... but I follow the hint and turn away the extract($_POST); – Diogo Rodrigues Jul 07 '15 at 11:32

0 Answers0