views:

280

answers:

1

Hi, I'm trying to send array of data from Flash to PHP to sending e-mail. I'd like to do that because I must change the php page everytime my form site changes because of client's choice.

My answer is, can I send an array of objects like this to php?

var message:Array = new Array ();
message.push ({field_name:"Name", value:"John Lennon"});
message.push ({field_name:"e-mail", value:"[email protected]"});
message.push ({field_name:"Message", value:"Hello goodbye"});

so, PHP should recive a string like:

[
    {
        "field_name":"Name",
        "value":"John Lennon"
    },{
        "field_name":"e-mail",
        "value":"[email protected]"
    },{
        "field_name":"Message",
        "value":"Hello goodbye"
    }
]

does exist some tecnique?

+2  A: 

this should do the job for you..

import com.adobe.serialization.json.JSON;

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;

var message:Array = new Array ();
    message.push ({field_name:"Name", value:"John Lennon"});
    message.push ({field_name:"e-mail", value:"[email protected]"});
    message.push ({field_name:"Message", value:"Hello goodbye"});

var vars: URLVariables = new URLVariables();
    vars.data   = JSON.encode(messages);

var req: URLRequest = new URLRequest();
    req.method      = URLRequestMethod.POST;
    req.data        = vars;
    req.url         = "yourdomain.com"

    ldr.addEventListener(Event.COMPLETE, handleServerResponse);
    ldr.load(req);

all you have to do is use the #json_decode method in php.. regards..

the binary
thank you very much!
Vittorio Vittori
you're welcome.. :)
the binary