Estimados amigos de este buen foro.
Estoy utilizando un plug-in para jquery, en la validación de un formulario, que lo que hace por el momento es mostrar advertencias sobre los campos respondiendo a reglas de validación configuradas. Hasta ahí bien!!!El problema es que uso ajax de JQ para procesar el formularios y no consigo que este plug-in detenga el envío en caso de error. Tiene un método "validate" para eso pero no estoy pudiendo usarlo. Agradeceré su apreciaciones al respecto.
Página de referencia del plug-in [URL="http://demos.usejquery.com/ketchup-plugin/index.html?db-skill=on&db-skill=on"]http://demos.usejquery.com/ketchup-plugin/index.html?db-skill=on&db-skill=on[/URL]
De momento mi formulario solo se detiene por campos vacíos
Código:
$(document).ready(function(){
$('#Formulario').ketchup({validateEvents: 'keyup focus'}, {
'#nombre' : 'required, minlength(2),maxlength(20)',
'#telefono' : 'required, minlength(6), maxlength(16), number',
'#email' : 'required, minlength(6), maxlength(40), email',
'#asunto' : 'required, minlength(6), maxlength(20)',
'#mensaje' : 'required, minlength(10), maxlength(800)',
});
var nombre = $("input#nombre").val();
var valid = $("input#nombre").ketchup('validate');
if (nombre == "" && valid==true) {
$("input#nombre").focus();
return false;
} ;
var email = $("input#email").val();
if (email == "") {
$("input#email").focus();
return false;
} ;
var telefono = $("input#telefono").val();
if (telefono == "") {
$("input#telefono").focus();
return false;
};
var asunto = $("input#asunto").val();
if (asunto == "") {
$("input#asunto").focus();
return false;
};
var mensaje = $("textarea#mensaje").val();
if (mensaje == "") {
$("textarea#mensaje").focus();
return false;
};
var checkeado=$("input:checkbox#noticias").attr("checked");
if(checkeado) {
var noticias="Mandame las noticias";
} else {
var noticias="No deseo recibir las noticiás gracias";
};
function verificar()
{
var dataString = 'nombre=' + nombre + '&email=' + email + '&telefono=' + telefono + '&asunto=' + asunto + '&mensaje=' + mensaje + '¬icias=' + noticias;
$.ajax(
{
contentType: "application/x-www-form-urlencoded",
type: "POST",
url: "send.php",
dataType: "html",
data: dataString,
async:true,
beforeSend: function(objeto, exito)
{
$("#ContendorFormularios_").html("<div id='enviado'></div>");
$("#enviado").html('<h3 class="Completando">Consulta Enviada!!!<br />Procesando<img src="imagenes/descarga.gif" width="32" height="32" title="descargas" /></h3>');
if(exito=="success"){
$("#ContendorFormularios_").html("<div id='Completo'></div>");
$("#Completo").html('<h3 class="Completando">Completado!!!Esperando confirmación</h3>');
}
},
success: function(msg) {
$("#ContendorFormularios_").html("<div id='final'></div>");
$("#final").fadeIn(
"slow",
function(){
$("#final").html(msg);
}
);
},
cache: false
}
);
};
$('#verificar').click( verificar );
});
P/D: Promotores del plug-in validate abstenerse de recomendaciones sobre le mismo Jajaja!!!