Bom dia,
preciso fazer o envio do formulário que for preenchido, na página tenho vários formulários e que apenas tenho que enviar o que vai ser preenchido. Gostaria de saber se o melhor jeito é fazer cada id para cada formulário e também um arquivo php para cada formulário?
HTML:
<form class="head-quote-seguro" method="post">
<p class="pclasse">formulario 1</p>
<input type="hidden" nome="seguro" id="seguro" value="Seguro 1">
<input type="text" class="form-control" name="quote-name" id="quote-name" placeholder="Nome" required />
<input type="text" class="form-control" name="quote-name" id="quote-name" placeholder="Nome" required />
<input type="email" class="form-control" name="quote-email" id="quote-email" placeholder="Email" required />
<input type="text" class="form-control tel" name="quote-telephone" id="quote-telephone" placeholder="Telefone"
required />
<textarea class="form-control" name="quote-message" id="quote-message" placeholder="O que precisa?" rows="2"
required></textarea>
<button type="submit" class="btn btn-primary btn-black btn-block">Enviar</button>
<!--Alert Message-->
<div id="head-quote-result" class="mt-xs">
</div>
</form>
<form class="head-quote-seguro" method="post">
<p class="pclasse">formulario 2</p>
<input type="hidden" nome="seguro" id="seguro" value="Seguro 2">
<input type="text" class="form-control" name="quote-name" id="quote-name" placeholder="Nome" required />
<input type="text" class="form-control" name="quote-name" id="quote-name" placeholder="Nome" required />
<input type="email" class="form-control" name="quote-email" id="quote-email" placeholder="Email" required />
<input type="text" class="form-control tel" name="quote-telephone" id="quote-telephone" placeholder="Telefone"
required />
<textarea class="form-control" name="quote-message" id="quote-message" placeholder="O que precisa?" rows="2"
required></textarea>
<button type="submit" class="btn btn-primary btn-black btn-block">Enviar</button>
<!--Alert Message-->
<div id="head-quote-result" class="mt-xs">
</div>
</form>
SCRIPT:
$(function () {
var frm = $(".head-quote-seguro");
frm.submit(function (e) {
$.ajax({
type: "POST",
url: "./form-seguros.php",
data: frm.serialize(),
success: function () {
$(".head-quote-seguro").append("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button><i class='fa fa-thumbs-o-up'></i><strong>Obrigado!</strong> Sua mensagem foi enviada!</div>")
}
}), e.preventDefault()
}), jQuery(".tap-title").each(function () {
jQuery(this).on('click', function () {
return jQuery(this).parent().parent().hasClass("toggle-accordion") ? (jQuery(this).parent().find("li:first .tap-title").addClass("active"), jQuery(this).parent().find("li:first .tap-title").next(".accordion-inner").addClass("active"), jQuery(this).toggleClass("active"), jQuery(this).next(".accordion-inner").slideToggle().toggleClass("active"), jQuery(this).find("i").toggleClass("fa-plus").toggleClass("fa-minus")) : jQuery(this).next().is(":hidden") ? (jQuery(this).parent().parent().find(".tap-title").removeClass("active").next().slideUp(200), jQuery(this).parent().parent().find(".tap-title").next().removeClass("active").slideUp(200), jQuery(this).toggleClass("active").next().slideDown(200), jQuery(this).next(".accordion-inner").toggleClass("active"), jQuery(this).parent().parent().find("i").removeClass("fa-minus").addClass("fa-plus"), jQuery(this).find("i").removeClass("fa-plus").addClass("fa-minus")) : (jQuery(this).toggleClass("active").next().slideToggle(200), jQuery(this).next(".accordion-inner").toggleClass("active"), jQuery(this).parent().parent().find("i").removeClass("fa-minus").addClass("fa-plus")), !1
})
});
});
$(function () {
var frm = $(".head-quote-form");
frm.submit(function (e) {
$.ajax({
type: "POST",
url: "./form-seguros.php",
data: frm.serialize(),
success: function () {
$(".head-quote-form").append("<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button><i class='fa fa-thumbs-o-up'></i><strong>Obrigado!</strong> Sua mensagem foi enviada!</div>")
}
}), e.preventDefault()
}), jQuery(".tap-title").each(function () {
jQuery(this).on('click', function () {
return jQuery(this).parent().parent().hasClass("toggle-accordion") ? (jQuery(this).parent().find("li:first .tap-title").addClass("active"), jQuery(this).parent().find("li:first .tap-title").next(".accordion-inner").addClass("active"), jQuery(this).toggleClass("active"), jQuery(this).next(".accordion-inner").slideToggle().toggleClass("active"), jQuery(this).find("i").toggleClass("fa-plus").toggleClass("fa-minus")) : jQuery(this).next().is(":hidden") ? (jQuery(this).parent().parent().find(".tap-title").removeClass("active").next().slideUp(200), jQuery(this).parent().parent().find(".tap-title").next().removeClass("active").slideUp(200), jQuery(this).toggleClass("active").next().slideDown(200), jQuery(this).next(".accordion-inner").toggleClass("active"), jQuery(this).parent().parent().find("i").removeClass("fa-minus").addClass("fa-plus"), jQuery(this).find("i").removeClass("fa-plus").addClass("fa-minus")) : (jQuery(this).toggleClass("active").next().slideToggle(200), jQuery(this).next(".accordion-inner").toggleClass("active"), jQuery(this).parent().parent().find("i").removeClass("fa-minus").addClass("fa-plus")), !1
})
});
});
PHP:
<script language= "JavaScript">
setTimeout("document.location = http://ninerscorretora.com.br",1000);
</script>
<?php
// Check for empty fields
if(empty($_POST['quote-name']) || empty($_POST['quote-telephone']) || empty($_POST['quote-message']) || empty($_POST['quote-email']) || !filter_var($_POST['quote-email'],FILTER_VALIDATE_EMAIL)){
echo json_encode(array('error'=>'true'));
return false;
}
$seguro = $_POST['seguro'];
$nome = $_POST['quote-name'];
$email = $_POST['quote-email'];
$telefone = $_POST['quote-telephone'];
$mensagem = $POST['quote-message'];
$subject = ($_POST['subject'] ? $_POST['subject'] : "Novo envio de formulário de contato");
// Create the email and send the message
$to = '[email protected]';// Add your email address inbetween the '' replacing [email protected] - This is where the form will send a message to.
$email_subject = $subject;
$email_body = "Tipo de seguro: $seguro <br><br>
Nome: $nome <br><br>
E-mail: $email <br><br>
Telefone: $telefone <br><br>
Mensagem: $mensagem";
$headers = "MIME-Version: 1.1\r\n".
"Content-type: text/html; charset=utf-8\r\n".
"Content-Transfer-Encoding: 8bit\r\n".
"From: ". $_POST['quote-name'] ." <". $_POST['quote-email'] .">\r\n".
"Reply-to: ". $_POST['quote-name'] ." <". $_POST['quote-email'] .">\r\n".
"Date: ". date( "r" );
mail($to,$email_subject,$email_body,$headers);
echo json_encode(array('Mensagem enviada com sucesso'));
return true;
?>