Comunidad de diseño web y desarrollo en internet online

Validacion y envio de correo

Citar            
MensajeEscrito el 24 Feb 2012 07:39 pm
Buenas estoy con la parte de programar para al darle enviar me valide los campos y mande el correo.... no tengo problema con la parte de envio, pero si con la de validdación... este es mi codigo:

Código ActionScript :

import fl.motion.MotionEvent;
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLLoader;


this.datosUser = new URLLoader();
this.respuesta = new URLLoader();
respuesta.onLoad= function() {
      if (this.error == 0) {
      } else {
      }
   };
   
this.isMail = function (arg){
   
   if (arg =="" || arg == null || arg == "null" || arg == undefined || arg == "undefined") {
      return false;
      
   } else if (arg.indexOf("@") == -1 || arg.indexOf("@") != arg.lastIndexOf("@")) {
      return false;
      
   } else {
      
      var partes = arg.split("@");
      var usuario = partes[0];
      var dominio = partes[1];
      
      if (usuario.length<1) {
         return false;
         
      } else {
         
         var caracteresProhibidos = new Array ("°", "ª", "!", "#", "$", "%", "&", "¬", "/", "(", ")", "=", "?", "¿", "¡", ",", ";", ":", "[", "]", "{", "}", "á", "à", "ñ", "~", "é", "è", "í", "ì", "ó", "ò", "ú", "ù", "Á", "À", "É", "È", "Í", "Ì", "Ó", "Ò", "Ù", "Ù", "Ç", "ç");
         var numCaracteresProhibidos = 0;
         for (var k = 0; caracteresProhibidos[k]; k++) {
            if (usuario.indexOf(caracteresProhibidos[k]) != -1) {
               numCaracteresProhibidos++;
            }
         }
         if (numCaracteresProhibidos>0) {
            
            return false;
            
         } else if (dominio.indexOf(".") == -1 || dominio.length<1) {
            return false;
            
         } else {
            var partes_dominio = dominio.split(".");
            var extension = partes_dominio[partes_dominio.length-1];
            
            if (dominio.length-extension.length<4) {
               
               return false;
            } else if (extension.length<2 || extension.length>4) {
               
               return false;
            } else {
               
               return true;
            }
         }
      }
   }
};

this.isBlank = function (valor) {
   
   if (valor == "" || valor == undefined || valor == null || valor.length<1) {
      return true;
   } else{
      return false;
      }
{
    
    if (isBlank(nombre_txt)) {
       
       _parent.submitForm_mc.avisar ("Por Favor Introducir Nombre");
       
    }else {
       
       if (isBlank(mail_txt)) {
          
         _parent.submitForm_mc.avisar ("Introducir Correo Electronico");
         
       } else {
          
          if (!isMail(mail_txt)) {
             
             _parent.submitForm_mc.avisar ("Correo Electronico Invalido");
             
          } else {
             
             if (isBlank(mensaje_txt)) {
                
                _parent.submitForm_mc.avisar ("Por Favor Introducir Mensaje");
                
             } else {
                
                function enviarCorreo(e:MotionEvent):void {
                
                
                
                var variables:URLVariables = new URLVariables();
                
                variables.nombre=nombre_txt.text;
                variables.email=mail_txt.text;
                variables.mensaje=mensaje_txt.text;
                
                var phpReq:URLRequest = new URLRequest("mail.php");
                
                phpReq.data = variables;
                phpReq.method = URLRequestMethod.POST;
                
                var loader:URLLoader = new URLLoader();
                loader.dataFormat= URLLoaderDataFormat.VARIABLES;
                loader.load(phpReq);
                
};



             }
          }
       }
    }
    
 }
}

Por simonroderix

7 de clabLevel



 

chrome
Citar            
MensajeEscrito el 25 Feb 2012 01:28 am
¿100 líneas de código para un formulario? ¿Cuantos campos estás enviando?
Tip: no encadenes if ... else al infinito, usa de a uno y si encuentras un error lo marcas, eje

Código ActionScript :

var error:String = ""
if(nombre.lenght < 3) error = "Debe poner el nombre";
if(isNaN(Number(edad.text)) error += "Debe poner su edad"
....
if(error==""){
  //envia
} else {
  //muestra mensaje de error
}


Tendrás menos código y mayor síntesis

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.