codigo del index
Código:
codigo del phpm que inserta los datos:<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <!-- <link rel="stylesheet" href="css/bootstrap.css" /> --> <link rel="stylesheet" href="css/jquery.fancybox.css" /> <link rel="stylesheet" href="css/style.css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="js/jquery.fancybox.js"></script> </head> <body> <div id="wrapper"> <h1>Welcome! Lets get this started...</h1> <p>Click the button below to try it out.</p> <p><a class="button modalbox" href="#inline">Contact Me</a></p> </div> <!-- hidden inline form --> <div id="inline"> <form id="contact" name="contact" action="" method="post"> <fieldset> <legend>Please complete the following form</legend> <label for="email"><span class="required">*</span> Email</label> <input name="email" type="email" id="email" class="txt" /> <br /> <label for="comments"><span class="required">*</span> Your comments</label> <textarea name="msg" id="msg"></textarea> <button id="send" class="button">Send E-mail</button> </fieldset> </form> </div> <script src="js/functions.js"></script> </body> </html>
Código:
y por ultimo el codigo del js.<?php $db=new mysqli('localhost','root','','ejemplo'); $stm=$db->prepare('INSERT INTO contacto(email,comentario) VALUES(?,?)'); $stm->bind_param('ss',$_POST['email'],$_POST['msg']); $res=$stm->execute(); if ($res) { echo 'true'; } esle{ echo "false"; } ?>
Código:
ahi esta el codigo, estoy utilizando el fancybox para mostrar el form, gracias nuevamnete... function validateEmail(email) { var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return reg.test(email); } $(document).ready(function() { $(".modalbox").fancybox(); $("#contact").submit(function() { return false; }); $("#send").on("click", function(){ var emailval = $("#email").val(); var msgval = $("#msg").val(); var msglen = msgval.length; var mailvalid = validateEmail(emailval); if (mailvalid == false) { $("#email").addClass("error"); } $("#email").change(function() { $("#email").removeClass("error"); }); if (msglen < 4) { $("#msg").addClass("error"); } $("#msg").change(function() { $("#msg").removeClass("error"); }); if (mailvalid == true && msglen >= 4) { $("#send").replaceWith("<em>sending...</em>"); $.ajax({ type: 'POST', url: 'enviar.php', data: $("#contact").serialize(), success: function(data) { if(data == "true") { $("#contact").fadeOut("fast", function(){ $(this).before("<p><strong>Success! Your message has been sent, thanks!</strong></p>"); setTimeout("$.fancybox.close()", 2000); }); } } }); } }); });