Data Capture Form With Remote ASP Server

Hi there…

Could anyone please help me with this problem? I’m making a small flash app that’s going to have a data capture form at the end. The problem is that it’s going to be hosted on someone else’s server and we need to capture the data ourselves. Our server is ASP and I really need the data from the form to be sent to us where it will be written to a database. - Is this possible at all? I’ve been looking into URLLoader and URLVariables but our tests aren’t working so far.

Here is the AS3 code I’m using in the flash file…

contact_name.text = contact_email.text = contact_subject.text = 
contact_message.text = message_status.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( "http://www.mysite/myfolder/getdetails.asp" );
URL_request.method = URLRequestMethod.POST;

function submit(e:MouseEvent):void
{
    if( contact_name.text == "" || contact_email.text == "" ||
        contact_subject.text == "" || contact_message.text == "" )
    {
        message_status.text = "Please fill in all text fields.";
    }
    else if( !validate_email(contact_email.text) )
    {
        message_status.text = "Please enter the valid email address.";
    }
    else
    {
        message_status.text = "sending...";
        
        var email_data:String = "name=" + contact_name.text
                       + "&email=" + contact_email.text
                       + "&subject=" + contact_subject.text
                       + "&message=" + contact_message.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
{
    contact_name.text = contact_email.text = contact_subject.text = 
    contact_message.text = message_status.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! You are now in the prize draw.";
        timer = new Timer(500);
        timer.addEventListener(TimerEvent.TIMER, on_timer);
        timer.start();
    }
    else
    {
        message_status.text = "Failed! Your message cannot send.";
    }
}

function on_timer(te:TimerEvent):void 
{
    if( timer.currentCount >= 10 )
    {
        contact_name.text = contact_email.text = contact_subject.text = 
        contact_message.text = message_status.text = "";
        timer.removeEventListener(TimerEvent.TIMER, on_timer);
    }
}

And here’s the ASP code in the page getdetails.asp

myname=request("contact_name")
email=request("contact_email")
subject=request("contact_subject")
message=request("contact_message")
 
response.write "Name:" & myname & "<BR>"
response.write "Subject: " & subject & "<BR>"
response.write "Email: " & email & "<BR>"
response.write "Message: " & message
 
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
objCDOSYSMail.From = "[email protected]"                
 
bodytext= message
 
objCDOSYSMail.To = email
 
objCDOSYSMail.Subject = subject         
 
objCDOSYSMail.TextBody = bodytext
 
objCDOSYSMail.Send
 
'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
 
'response.redirect Server.URLEncode("emailtest.html?yes")
response.write "success=yes"

If anyone could shed any light on this it would be much appreciated!

Thanks :slight_smile: