Doubt about POST and GET in php

4

I tried searching the internet, but I could not answer my question ... I started programming the web recently, although I already used post and get, I came across a situation where I got "packed". I have the page cadastrar_endereco.php, which is nothing more than a form with fields of texts for street, neighborhood, cep and etc ...  But this form has 2 buttons, the Search Cp, which opens search_cep.php that searches the zip that the user typed and saves in sessions, and returns cadastrar_endereco.php with the other fields already filled in, but also has the save button, which sends the values typed into the DB ... The problem is that the zip code field is in a POST method for the get_cep.php, while the other fields are in the save.php Also via post, so I can not Save the zip in the BD ..... I wonder if it would have like me to put everything in one, or send the zip via get to the search_cep.php, since it is a small information and does not require privacy ... < p>     

asked by anonymous 07.04.2014 / 23:00

1 answer

6

One possible solution would be to use this structure:

Página PHP com o formulário 
|
+- If cliente clicou em "buscar cep"
|  |
|  +- Include "buscacep.php"
|     Que busca o endereço do cep e substitui as variáveis pegas com POST
|     Continua normalmente até mostrar o form
|
+- Else If cliente clicou em "enviar"
|  |
|  +- Include "salvanodb.php"
|     Que verifica se está tudo em ordem.
|     |
|     +- Se estiver, salva, redireciona para página de sucesso ( e die(); )
|     |
|     +- Se estiver faltando algo, guarda mensagem de erro em uma variável.
|        Nesse caso, nada de die(); que é pra continuar no form
|
+- Mostra o formulário, com os valores anteriormente digitados no value="" dos inputs
    
07.04.2014 / 23:28