0
I have a form with dynamic fields. with inputs with Names like this:
<input type="hidden" name="nome_prod1" value="Shampoo Hidratante Dazen Elegance">
<input data-theme="b" value="0" name="qtd1" type="text" id="1"/>
<input type="hidden" name="nome_prod2" value="Shampoo Hidratante Dazen Elegance">
<input data-theme="b" value="0" name="qtd2" type="text" id="1"/>
each one with its value, the problem is at the time of showing this because did not want to show so little save in the bank the fields that have quantity 0
.
I used the command:
foreach( $_POST as $nome_campo => $valor)
{
$comando = "$" . $nome_campo . "='" . $valor . "';";
eval($comando);
}
However he brought all the inputs, I tried to treat not to show the ones that have qtd = 0
but the problem is in finding the variable I put a counter $i
within foreach
, then the variable name qtd
I tried to call it that:
if ($qtd{$i} == 0 ) {}
But it didn’t work, as I do it fetching a dynamic variable?
$qtd1
$qtd2
$qtd3
I do not know if I understood the question well, but it would not be the case to use
extract
?– Papa Charlie
@Papacharlie would be if it was to encourage his first idea, which I condemn. It’s that in Extract you can’t give it for an IF as I mentioned above, either take everything or take nothing. Eval, Extract, $_REQUEST, $$variables and everything that is very "generic" in PHP ends up being a big problem. But if you post an example with Extract, I think it’s a valid alternative (which I don’t recommend, but wouldn’t be wrong). I just suggest making it clear that you suffer from the same problems I mentioned above. Anyway, it is a valid comment.
– Bacco
I know, I agree 1000%, and I wouldn’t dare answer using
extract
. The ideal would be to recommend a more correct approach as you did. I was the one who didn’t understand the question, I wanted to know if what I needed was in line withextract
.– Papa Charlie
@Papacharlie in this case, I put a mention to your comment in the reply, at least it is not missing to warn of the option.
– Bacco