Código Javascript:
Ver original
function nuevoAjax(){ var xmlhttp=false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } return xmlhttp; } function borrarCampos(){ document.enviar_email.reset(); } function enviarMail(){ c = document.getElementById('div-mensaje'); emis=document.enviar_email.author.value; mail=document.enviar_email.email.value; url=document.enviar_email.url.value; cues=document.enviar_email.cuestion.value; mens=document.enviar_email.comment.value; ajax=nuevoAjax(); //c.innerHTML = '<p style="text-align:center;"><img src="img/load.gif"/></p>'; ajax.open("POST", "php/envia_mail.php",true); ajax.onreadystatechange=function() { if (ajax.readyState==4) { c.innerHTML = ajax.responseText } borrarCampos() } ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); ajax.send("author="+emis+"&email="+mail+"&url="+url+"&cuestion="+cues+"&mensaje="+mens) } function validar(formulario) { var remitente = document.getElementById("author").value; var email = document.getElementById("email").value; var web = document.getElementById("url").value; var asunto = document.getElementById("cuestion").value; var mensaje = document.getElementById("comment").value; var nombre = /(^([a-zA-Z]{1,4}\.\s)?[a-zA-Z\s\u00D1\u00F1\u00E1\u00E9\u00ED\u00F3\u00FA\u00C1\u00C9\u00CD\u00D3\u00DA]{10,400}$)/; var mail = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; var cadena = /(^[a-zA-Z0-9\s\u00D1\u00F1\u00E1\u00E9\u00ED\u00F3\u00FA\u00C1\u00C9\u00CD\u00D3\u00DAu0021\u0022\u0023\u0024\u0025\u0026\u0027\u0028\u0029\u002B\u002C\u002D\u002E\u002F\u003A\u003B\u003F\u0040\u00A1\u00BF]{10,400}$)/; if (!nombre.test(remitente)) { document.getElementById("div-mensaje").innerHTML = "<font color=red>Por favor verifique el campo obligatorio.</font>"; document.getElementById('author').style.border = "1px solid red"; document.getElementById('email').style.border = "1px solid #ccc"; document.getElementById('comment').style.border = "1px solid #ccc"; document.getElementById("author").focus(); return false; } else if (!mail.test(email)) { document.getElementById("div-mensaje").innerHTML = "<font color=red>Por favor verifique el campo obligatorio.</font>"; document.getElementById('author').style.border = "1px solid #ccc"; document.getElementById('email').style.border = "1px solid red"; document.getElementById('comment').style.border = "1px solid #ccc"; document.getElementById("email").focus(); return false; } else if (!cadena.test(mensaje)) { document.getElementById("div-mensaje").innerHTML = "<font color=red>Por favor verifique el campo obligatorio.</font>"; document.getElementById('author').style.border = "1px solid #ccc"; document.getElementById('email').style.border = "1px solid #ccc"; document.getElementById('comment').style.border = "1px solid red"; document.getElementById("comment").focus(); return false; } enviarMail(); return false; }
Gracias de antemano