derrida
asked on
AS3 problem with sending variables
hi
i have a form that i want to send its variables to a php file.
so i have this code in flash:
//------------------------ -------INS ERTING---- ---------- ---------- ---------- --\\
insertit.addEventListener( MouseEvent .CLICK, sendTheData);
function sendTheData (ev:MouseEvent) {
var myReq:URLRequest= new URLRequest("insertit.php") ;
myReq.method= URLRequestMethod.POST;
var myVars:URLVariables= new URLVariables();
myVars.firstNAME = fNAME.text;
myVars.email = EMAIL.text;
myVars.phone = PHONE.text;
myVars.lastNAME = lNAME.text;
myReq.data=myVars;
trace(myReq.data);
var myLoader:URLLoader= new URLLoader();
myLoader.dataFormat= URLLoaderDataFormat.VARIAB LES;
myLoader.addEventListener( Event.COMP LETE, tellMe);
myLoader.load(myReq);
}
function tellMe (ev:Event) {
}
and for now the php file only take the variables and does not do anything with it.
when i try to send the data i get this message in the output:
firstNAME=shimon&phone=458 76578346&l astNAME=pe res&email= peres%40wa lla%2Ecom
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
the first line is my trace and it shows thet it does come as name\value pair. so i have no idea what to do with the error message.
help will be very appriciated.
best regards
ron
i have a form that i want to send its variables to a php file.
so i have this code in flash:
//------------------------
insertit.addEventListener(
function sendTheData (ev:MouseEvent) {
var myReq:URLRequest= new URLRequest("insertit.php")
myReq.method= URLRequestMethod.POST;
var myVars:URLVariables= new URLVariables();
myVars.firstNAME = fNAME.text;
myVars.email = EMAIL.text;
myVars.phone = PHONE.text;
myVars.lastNAME = lNAME.text;
myReq.data=myVars;
trace(myReq.data);
var myLoader:URLLoader= new URLLoader();
myLoader.dataFormat= URLLoaderDataFormat.VARIAB
myLoader.addEventListener(
myLoader.load(myReq);
}
function tellMe (ev:Event) {
}
and for now the php file only take the variables and does not do anything with it.
when i try to send the data i get this message in the output:
firstNAME=shimon&phone=458
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
the first line is my trace and it shows thet it does come as name\value pair. so i have no idea what to do with the error message.
help will be very appriciated.
best regards
ron
ASKER
hi
this cannot be the answer since i need this data as variables and not loading it as text.
you see in the php file i need to get back the fact that it was made so in it there is this code:
$fname= $_POST['firstNAME'];
$lname= $_POST['lastNAME'];
$phone= $_POST['phone'];
$email= $_POST['email'];
if ($fname != "" && $lname != "" && $phone != "" && $email != "") {
echo "writing=ok&";
}else{
echo "writing=error";
}
so in flash i can check it:
function tellMe (ev:Event) {
if (ev.target.data.writing== "ok") {
insert_error_txt.text= "the data was sent and inserted";
}
if (ev.target.data.writing== "error") {
insert_error_txt.text= "the data was NOT sent and inserted";
}
}
ron
this cannot be the answer since i need this data as variables and not loading it as text.
you see in the php file i need to get back the fact that it was made so in it there is this code:
$fname= $_POST['firstNAME'];
$lname= $_POST['lastNAME'];
$phone= $_POST['phone'];
$email= $_POST['email'];
if ($fname != "" && $lname != "" && $phone != "" && $email != "") {
echo "writing=ok&";
}else{
echo "writing=error";
}
so in flash i can check it:
function tellMe (ev:Event) {
if (ev.target.data.writing== "ok") {
insert_error_txt.text= "the data was sent and inserted";
}
if (ev.target.data.writing== "error") {
insert_error_txt.text= "the data was NOT sent and inserted";
}
}
ron
These look like your problem, I faintly remember getting that error a while ago, can't remember how I resolved it, but I have a feeling I did do the above.
Have a look at the links see what you think.
http://www.kirupa.com/forum/showthread.php?t=277069
http://www.flashmove.com/board/showthread.php?t=31762
http://board.flashkit.com/board/showthread.php?t=737310&highlight=url-encoded
Let me know.
Have a look at the links see what you think.
http://www.kirupa.com/forum/showthread.php?t=277069
http://www.flashmove.com/board/showthread.php?t=31762
http://board.flashkit.com/board/showthread.php?t=737310&highlight=url-encoded
Let me know.
try changing your code to this
var myReq:URLRequest= new URLRequest("insertit.php") ;
myReq.method= URLRequestMethod.GET;
var myVars:URLVariables= new URLVariables();
myVars.firstNAME = fNAME.text;
myVars.email = EMAIL.text;
myVars.phone = PHONE.text;
myVars.lastNAME = lNAME.text;
myReq.data=myVars;
trace(myReq.data);
var myLoader:URLLoader= new URLLoader(myReq);
i know GET is less secure but if you're not sending sensitive information it should be fine. i've had problems sending information from etxt fields using POST recently too. of course you'll have to change your php code to to $_get for each variable being sent
var myReq:URLRequest= new URLRequest("insertit.php")
myReq.method= URLRequestMethod.GET;
var myVars:URLVariables= new URLVariables();
myVars.firstNAME = fNAME.text;
myVars.email = EMAIL.text;
myVars.phone = PHONE.text;
myVars.lastNAME = lNAME.text;
myReq.data=myVars;
trace(myReq.data);
var myLoader:URLLoader= new URLLoader(myReq);
i know GET is less secure but if you're not sending sensitive information it should be fine. i've had problems sending information from etxt fields using POST recently too. of course you'll have to change your php code to to $_get for each variable being sent
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change the above line to:
myLoader.dataFormat = URLLoaderDataFormat.TEXT;