Last active
August 24, 2019 17:15
-
-
Save taciara/660015b061bf385e0966148d698fd7da to your computer and use it in GitHub Desktop.
Validação de formulário simples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- No HTML --> | |
| <form id="contactForm2" action="enviar.php" method="post"> | |
| <label class="my-2">Nome para contato:</label> | |
| <input class="form-control" type="text" name="Name" placeholder="Nome Completo" required=""> | |
| <label>Informe seu e-mail:</label> | |
| <input class="form-control" type="email" name="Email" placeholder="E-mail" required=""> | |
| <label class="my-2">Escolha o tipo de plano:</label> | |
| <select name="Subject" class="form-control"> | |
| <option value="">Plano de Saúde para Empresa</option> | |
| <option value="">Plano de Saúde Individual</option> | |
| <option value="">Plano de Saúde Familiar</option> | |
| <option value="">Seguro de Vida</option> | |
| </select> | |
| <label>Mensagem:</label> | |
| <textarea id="textarea" placeholder="Deixe aqui sua mensagem" required=""></textarea> | |
| <input class="form-control" type="submit" value="Solicitar uma cotação"> | |
| </form> | |
| <!-- NO JS --> | |
| <script> | |
| var formsAll = document.querySelectorAll('form'); | |
| for (var i = 0; i < formsAll.length; i++) { | |
| var form = formsAll[i]; | |
| form.onsubmit = function(){ | |
| var formData = $( this ).serializeArray(); | |
| $.ajax({ | |
| url:'enviar.php', | |
| method:'POST', | |
| data:formData, | |
| success:function(response){ | |
| response = JSON.parse(response); | |
| if(response.status=="success") | |
| window.location = 'index.html'; | |
| else | |
| alert(response.msg); | |
| }, | |
| error:function(response){ | |
| alert("Erro ao enviar a mensagem"); | |
| } | |
| }); | |
| return false; | |
| } | |
| } | |
| </script> | |
| <!-- NO PHP --> | |
| <?php | |
| $to = 'contato@designmultimidia.com'; | |
| $sender = $to; | |
| $subject = "Novo contato LP"; | |
| // Request | |
| $name = isset($_POST['name'])?$_POST['name']:''; | |
| $email = isset($_POST['email'])?$_POST['email']:''; | |
| $plano = isset($_POST['plano'])?$_POST['plano']:''; | |
| //$assunto = isset($_POST['assunto'])?$_POST['assunto']:''; | |
| //$ddd = isset($_POST['ddd'])?"(".$_POST['ddd'].") ":''; | |
| //$mobile = isset($_POST['mobile'])?$_POST['mobile']:''; | |
| // $message = isset($_POST['message'])nl2br($_POST['message']):''; | |
| $message = isset($_POST['message'])?nl2br($_POST['message']):''; | |
| $page = $_SERVER['SERVER_NAME']; | |
| $body = "<h1>".$subject."</h1>" | |
| ."<strong>".$page."</strong>" | |
| ."<br /><br />" | |
| ."<strong>Nome: </strong>".$name."<br>" | |
| ."<strong>Email: </strong>".$email." <br>" | |
| ."<strong>Plano: </strong>".$plano." <br>" | |
| //."<strong>Telefone: </strong>".$mobile."<br>" | |
| //."<strong>Telefone: </strong>".$ddd.$mobile."<br>" | |
| //."<strong>Assunto: </strong>".$assunto."<br>" | |
| ."<strong>Mensagem: </strong>".$message."<br>" | |
| ."<strong>Uma landing page feita orgulhosamente pela Design Multimidia!</strong>"; | |
| /* headers adicionais */ | |
| $headers = "Content-type:text/html; charset=utf-8\n"; | |
| $headers .= "From: Novo contato <$sender>\r\n"; | |
| $headers .= "Bcc: taciara.furtado@gmail.com, clients@designmultimidia.com\r\n"; | |
| $headers .= "Return-Path:$sender\r\n"; | |
| $headers .= "Reply-To:$email\r\n"; | |
| $send = mail($to, $subject, $body, $headers,'-f'.$sender); | |
| if($send){ | |
| $resultmsg = 'Sua mensagem foi enviada com sucesso'; | |
| $status = 'success'; | |
| }else{ | |
| $status = 'error'; | |
| $resultmsg = 'Erro no envio de sua mensagem'; | |
| } | |
| echo json_encode(array('status'=>$status,'name'=>$name,'msg'=>$resultmsg)); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment