1
I have a contact form next to a google map. So far blz. But I’m catching in AJAX to make that when someone clicks in SEND appear an awesome font Gear and when successfully completed appear an awesome font check and clear the form.
CSS:
* {
box-sizing: border-box;
}
/* Style inputs */
input[type=text], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
cursor: pointer;
font-size: 0.7em;
}
input[type=submit]:hover {
background-color: #45a049;
}
/* Style the container/contact section */
.container2 {
border-radius: 5px;
background-color: #f2f2f2;
padding: 10px;
}
/* Create two columns that float next to eachother */
.column {
float: left;
width: 50%;
margin-top: 6px;
padding: 20px;
font-size: 0.7em !important;
color: #000;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
@media screen and (max-width: 600px) {
.column, input[type=submit] {
width: 100%;
margin-top: 0;
}
}
HTML:
<div align="center">
<div class="container2">
<div class="row">
<div class="column">
<div id="map" style="width:100%;height:600px"></div>
</div>
<div class="column" align="left">
<form action="contato.php" method="POST" id="contactform">
<label for="fullname">Seu nome</label>
<input type="text" id="fullname" name="fullname" placeholder="Nome" required>
<label for="email">E-mail</label>
<input type="text" id="email" name="email" placeholder="E-mail" required>
<label for="assunto">Assunto</label>
<input type="text" id="assunto" name="assunto" placeholder="Assunto" required>
<label for="mensagem">Mensagem</label>
<textarea id="mensagem" name="mensagem" placeholder="Escreva alguma coisa" style="height:170px"></textarea>
<div align="right">
<input type="submit" value="Enviar">
</div>
<br />
</form>
</div>
<div align="center" id="resp"></div>
</div>
</div>
JAVASCRIPT:
$('#contactform').submit(function(e) {
e.preventDefault();
const nome = $('input[name="fullname"]').val();
const email = $('input[name="email"]').val();
const assunto = $('input[name="assunto"]').val();
const mensagem = $('textarea[name="mensagem"]').val();
$.ajax({
url: 'contato.php', // caminho para o script que vai processar os dados
type: 'POST',
data: {nome: nome, email: email, assunto: assunto, mensagem: mensagem},
beforeSend: function() {
$("input[type='submit']").attr('disabled', 'disabled');
},
complete: function() {
},
success: function(response) {
$('#resp').html(response);
},
error: function(xhr, status, error) {
alert(xhr.responseText);
}
});
return false;
});
If there’s anything missing I put on!
Visually it is so:
Figure 1 - Form ready to be filled out
Figure 2 - fa fa-spin fa-Cog running while it is sent to contact.php
Figure 3 - fa fa-check for when to finish and then return to figure 1 state
Would be in that div
id="resp"
or not?– Sam
It can be or any other that brings everything the way I want! = D
– Gustavo