Foros del Web » Programando para Internet » PHP »

modal form

Estas en el tema de modal form en el foro de PHP en Foros del Web. hola amigos espero que em puedan ayudar, tengo un form modal que despliego para que me guarde unos datsoe n mi mysql pero, al darle ...
  #1 (permalink)  
Antiguo 31/05/2013, 14:57
 
Fecha de Ingreso: abril-2011
Ubicación: lima
Mensajes: 134
Antigüedad: 13 años
Puntos: 3
modal form

hola amigos espero que em puedan ayudar, tengo un form modal que despliego para que me guarde unos datsoe n mi mysql pero, al darle click no hace nada, aki les dejo el codigo; espero que mepuedan ayudar es urgente, es para un trabajo de la universidad. Gracias de antemano


codigo del index

Código:
<!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>
codigo del phpm que inserta los datos:

Código:
<?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";
}
 ?>
y por ultimo el codigo del js.

Código:
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);
						});
					}
				}
			});
			
		}
	});
});
ahi esta el codigo, estoy utilizando el fancybox para mostrar el form, gracias nuevamnete...
__________________
Solitary wolf..[email protected]
  #2 (permalink)  
Antiguo 06/06/2013, 12:31
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: modal form

Consulta un for JS o Ajax primero para ver por que no funciona.
__________________
Fere libenter homines, id quod volunt, credunt.

Etiquetas: form, html, modal, mysql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:39.