Jump to content

Envio de formulario


tmwh

Recommended Posts

Boas a todos. Estou a alterar um formulario em flash que inicialmente era enviado por email atraves de php (send_email.php). O que pretendia era em vez de enviar por email, introduzir os dados em DB. Tenho a função (inserir_dados.php) para esse efeito e que já funcionou anteriormente em html. Penso que os dados não estão a chegar à função (inserir_dados.php) pois nada é introduzido na DB. Penso que talvez seja a função (function receive_response) que seja a responsável pois fica à espera de resposta, mas como percebo muito pouco de actionscript decidi pedir ajuda.

Segue o código:

message_status.text = contact_nome.text =

contact_email.text = "";

send_button.addEventListener(MouseEvent.CLICK, submit);

reset_button.addEventListener(MouseEvent.CLICK, reset);

var timer:Timer;

var var_load:URLLoader = new URLLoader;

var URL_request:URLRequest = new URLRequest( "inserir_dados.php" );

URL_request.method = URLRequestMethod.POST;

function submit(e:MouseEvent):void

{

if( contact_nome.text == "" )

{

message_status.text = "Preencha correctamente os campos.";

}

else if( !validate_email(contact_email.text) )

{

message_status.text = "Introduza um email válido.";

}

else

{

message_status.text = "A enviar...";

var email_data:String = "&nome=" + contact_nome.text

+ "&email=" + contact_email.text;

var URL_vars:URLVariables = new URLVariables(email_data);

URL_vars.dataFormat = URLLoaderDataFormat.TEXT;

URL_request.data = URL_vars;

var_load.load( URL_request );

var_load.addEventListener(Event.COMPLETE, receive_response );

}

}

function reset(e:MouseEvent):void

{

message_status.text = contact_nome.text =

contact_email.text = "";

}

function validate_email(s:String):Boolean

{

var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;

var r:Object = p.exec(s);

if( r == null )

{

return false;

}

return true;

}

function receive_response(e:Event):void

{

var loader:URLLoader = URLLoader(e.target);

var email_status = new URLVariables(loader.data).success;

if( email_status == "yes" )

{

message_status.text = "Success! Your message was sent.";

timer = new Timer(500);

timer.addEventListener(TimerEvent.TIMER, on_timer);

timer.start();

}

else

{

message_status.text = "Failed! Your message cannot sent.";

}

}

function on_timer(te:TimerEvent):void

{

if( timer.currentCount >= 10 )

{

message_status.text = contact_nome.text =

contact_email.text = "";

timer.removeEventListener(TimerEvent.TIMER, on_timer);

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.