Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

rcamu

melhorar um formulario

Recommended Posts

Pessoal sou novato em programação e estou aprendendo muitas coisas agora...preciso da ajuda de você´s para melhorar um formulário que fiz para dar saída de material do estoque.

 

O formulário montei funciona direitinho, agora queria melhorar ele mas não sei fazer.

 

Eu tenho vários campos nesse formulário inclusive os campos de produtos, quantidade e valor total do item.

 

O que acontece é o seguinte:

 

Quando a NF tem mais de 1 item tenho que ficar dando entrada na mesma nf varias vezes até entrar com todos os itens.

 

O que eu preciso é o seguinte:

 

Qdo a NF tiver mais de 1 item tenha a opção no formulário tipo um botão adicionar mais campos que seriam somente produto, valor unitário e total .

 

No banco pode duplicar as linhas como já ocorre hoje ai eu unifico no relatório que montei.

 

Poderiam ma ajudar a incluir essa função?

 

Segue abaixo o formulário, os campos que preciso duplica são: Produto, Quantidade, unitário e total.

 

 

<head><form form id="cad" name="cad" method="post" action="?mes=<?php echo $mes_hoje?>&ano=<?php echo $ano_hoje?>" onsubmit="return checa_formulario(this)" ><input type="hidden" name="acao" value="1" /><strong><b><font size="3"> <font color="#000000">Data :</font></strong><input type="text" name="data" size="11" maxlength="10" value="<?php echo date('d')?>/<?php echo $mes_hoje?>/<?php echo $ano_hoje?>" /> <br><br><strong><b><font size="3"> <font color="#000000">Cliente : <input type="text" required name="cliente" size="30" maxlength="50" /><strong><b><font size="3"> <font color="#000000">Usuario ML : <input type="text" required name="userml" size="25" maxlength="50" /><br><br><strong><b><font size="3"> <font color="#000000">Objeto : <input type="text" required name="objeto" size="20" maxlength="30" onkeyup="maiuscula(this)"/><strong><b><font size="3"> <font color="#000000">Entregue :</strong><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="entrega" value="Não" id="entrega" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>"/> Não</label><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="entrega" value="Sim" id="entrega" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>"/> Sim</label><br><br>

<strong><b><font size="3"> <font color="#000000">Produto :</strong><select name="cat"><?phpwhile ($row=mysql_fetch_array($qr)){?><option value="<?php echo $row['id']?>"><?php echo $row['nome']?></option><?php }?></select></select><br><br><strong><b><font size="3"> <font color="#000000">Quantidade :<input name="qtd" required type="text"  id="qtd" onKeyPress="return Numero(event)" maxlength="30"><strong><b><font size="3"> <font color="#000000">Unitário :<input name="valorund" type="text" required maxlength="30" id="valorund"value="0.00"onblur="Calc()"'/><strong><b><font size="3"> <font color="#000000">Total :<input name="total" type="text" required maxlength="30" id="total"'/><br><br>

<strong><b><font size="3"> <font color="#000000">Valor Frete : <input type="text" value="<?php echo dinheiro_br( $row['valorfrete'])?>" name="valorfrete" size="8" maxlength="10" /><br><br><strong><b><font size="3"> <font color="#000000">Nota Fiscal : <input type="text" required name="nf" onKeyPress="return Numero(event)" size="10" maxlength="10" /><br><br><strong><b><font size="3"> <font color="#000000">Valor Frete Real : <input type="text" id="valorfretereal" value="<?php echo dinheiro_br( $row['valorfretereal'])?>"name="valorfretereal" size="10" maxlength="10" /><br><br><strong>Local :</strong><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="local" value="Site" id="local" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>"/> Site</label><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="local" value="ML" id="local" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>"/> Mercado Livre</label><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="local" value="Fone" id="local" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>" /> Fone</label><br><br><strong><b><font size="3"> <font color="#000000">Tipo de Pagamento :</strong><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="tppgto" value="Mercado Pago" id="tppgto" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>"/> Mercado Pago</label><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="tppgto" value="Dinheiro" id="tppgto" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>"/> Dinheiro</label><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="tppgto" value="Boleto" id="tppgto" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>" /> Boleto</label><label for="tipo_despesa" style="color:#C00"><input type="radio" required name="tppgto" value="Crédito em Conta" id="tppgto" value="<?php if (sizeof($error) != 0) { echo $tipo; } ?>" /> Crédito em Conta</label><br><br><strong><b><font size="3"> <font color="#000000">Observação :</strong><br /><input type="text" required name="descricao" size="100" maxlength="90" value="<?php if (sizeof($error) != 0) { echo $descricao; } ?>" /><br><br><p><input type="submit" value="Cadastrar" /></p></form>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Faça isso usando jQuery, vai sair mais ou meno assim:

 

Crie um botão assim:

<button type="button" id="adicionar-campo">Adicionar Item</button>

Agora adicione um evento nesse botão usando jQuery assim:

$('#adicionar-campo').click(function() {
    // lista-de-campos é a ID da tag HTML que vai conter a lista de campos 
    // para a pessoa adicionar todos os itens de uma só vez
    $('#lista-de-campos').append('<input type="text" name="item[]" />');
});
Agora quando você enviar o formulario, o PHP vai receber uma array com todos os itens
foreach($_POST['item'] as $item) {
    // aqui você coloca seu codigo
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.