Comunidad de diseño web y desarrollo en internet online

Formulario AC3 y php

Citar            
MensajeEscrito el 26 May 2009 04:28 pm
Hola gente del foro. Soy nuevo aqui, tambien lo soy en flash jeje.
Les cuento que realice una animacion, a la cual al final le agregue un formulario. Mi problema es que cuando aprieto el boton login del formulario al parecer no pasa nada. SIn embargo, si luego entro a otro pagina sucede que la accion del login funciono. Lo que yo quiero que suceda es que al apretar el login, me rediriga automaticamente a la pagina que yo quiero. (Aclaro que si el login es en html/php funciona perfecto).Otra aclaracion, el submit_btn lo probe siendo mc y como boton sin obtener el resultado esperado.
Les dejo mi codigo de AS3.

Código :

stop();
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.sendToURL;
submit_btn.addEventListener(MouseEvent.MOUSE_DOWN, onEnviar);
 submit_btn.buttonMode = true;
submit_btn.useHandCursor = true;       
 
   function onEnviar(obj:Event) {
    var urlVars:URLVariables = new URLVariables();
    urlVars.usuario = usuario.text;
    urlVars.password = password.text;
    var urlRequ:URLRequest = new URLRequest("validar_usuario.php");
      urlRequ.method = URLRequestMethod.POST;
   urlRequ.data = urlVars;
   var urlLoad:URLLoader = new URLLoader();
   urlLoad.load(urlRequ);
      }


Aca les dejo mi php por las dudas.

Código :

<? // Pedazo de codigo para entrar a la base de datos
if(trim($HTTP_POST_VARS["usuario"]) != "" && trim($HTTP_POST_VARS["password"]) != "")
{
   // Puedes utilizar la funcion para eliminar algun caracter en especifico
   //$usuario = strtolower(quitar($HTTP_POST_VARS["usuario"]));
   //$password = $HTTP_POST_VARS["password"];
   // o puedes convertir los a su entidad HTML aplicable con htmlentities
   $usuario = strtolower(htmlentities($HTTP_POST_VARS["usuario"], ENT_QUOTES));
   $password = $HTTP_POST_VARS["password"];
   $result = mysql_query('SELECT password, usuario FROM usuarios WHERE usuario=\''.$usuario.'\'');
   if($row = mysql_fetch_array($result)){
      if($row["password"] == $password){
         $_SESSION["k_username"] = $row['usuario'];
            $_SESSION["k_password"] = $row['password'];
           header ("Location: listadevideos.php");
//         echo 'Has sido logueado correctamente '.$_SESSION['k_username'].' <p>';
//         echo '<a href="index.php">Index</a></p>';

      }else{
         echo 'Password incorrecto';
      }
   }else{
      echo 'Usuario no existente en la base de datos';
   }
   mysql_free_result($result);
}else{
   echo 'Debe especificar un usuario y password';
}
mysql_close();
?>


Por ultimo les quiero decir, que he probado un formulario en as2 ( que no puedo utilizar en mi caso ya que esta todo lo demas hecho con as3 y se complicaria demasiado adaptarlo) y al principio tenia el mismo problema con este codigo:

Código :

stop();

// Create 2 LoadVars objects to load and send data to the PHP script
var loader:LoadVars = new LoadVars();
var sender:LoadVars = new LoadVars();

status = "Enter your information and submit";

// When the submit button is pressed...
submit_btn.onRelease = function() {
    // assign the text in the input fields to the sender object
    sender.usuario = usuario.text;
    sender.password = password.text;
   
    
    // and then send it on to the PHP file on the server using
    // the POST method.  The returned result will be caught
    // by the loader object
    sender.sendAndLoad("validar_usuario.php", loader, "POST");
}

// The loader object waits for a response from the server
// and checks for any returned variables, messages, errors.
loader.onLoad = function(success:Boolean)
{
    // This boolean variable (success) will return true or false
    // on whether the PHP file was retrieved
    if(success)
    {
        // If we're here then we've successfully retrieved
        // the PHP file.  Lets check for a Login result
        if(this.checklog == 1)
        {
            // This is a authorised login so show the success frame
            // and show the message in the status textfield
            status = this.status;
            _parent.gotoAndStop("Success");
        }
        else if(this.checklog == 2)
        {
            // This is a unauthorised login so show the failure frame
            // and show the error message in the status textfield
            status = this.status;
            _parent.gotoAndStop("Invalid");
        }
    }
    else {
        // There was a problem retrieving the PHP file
        status = "Error connecting to server";
    }
}


y luego lo solucione cambiando

Código :

sender.sendAndLoad("validar_usuario.php", loader, "POST");

por

Código :

sender.send("validar_usuario.php", loader, "POST");


Esto lo pongo para ver si hay alguna semejanza en as3.
Muchas gracias a todos
Matias

Por matucasal

3 de clabLevel



 

firefox
Citar            
MensajeEscrito el 26 May 2009 05:50 pm
Básicamente lo que hace el PHP es redirigir si los credenciales son correctos:

header ("Location: listadevideos.php");

Dado que Flash espera una respuesta y no una redirección, evidentemente no funcionará. Haz que el PHP devuelva un valor que le indique a Flash que hacer (aunque sea redirigir) Si quieres solucionarlo como lo tenías en AS2, puedes hacer:

En vez de

urlLoad.load(urlRequ);

Pon

navigateToURL(urlRequ)

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 26 May 2009 09:15 pm
Funciona.
Solo mi ultima duda, cuando pongo click me hace todo en otra ventana, hay algunaforma de que no salga de esa ventana, y lo haga en la misma?

Por matucasal

3 de clabLevel



 

firefox
Citar            
MensajeEscrito el 26 May 2009 09:47 pm
Dale a F1 y busca en la ayuda navigateToURL, creo que el segundo parámetro tiene que ser "_self"

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 26 May 2009 11:00 pm
Buenisimo
Era con el "_self"
Gracias a ambos, los volvere a molestar prontamente :D jaja adios

Por matucasal

3 de clabLevel



 

firefox
Citar            
MensajeEscrito el 27 May 2009 11:03 am
¿Gracias a ambos?

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 27 May 2009 08:24 pm
jaja gracias jorge, no habia leido que el primero tambien lo habias mandado vos.

Por matucasal

3 de clabLevel



 

firefox

 

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