Welcome, Guest. Please login or register.
Did you miss your activation email?
02/07/12, 09:08
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  PHP, Perl, ASP, JSP, CFM (Moderators: Flash-db, Musicman, vesa kortelainen, Ronald Wernecke, Jorge Solis, nothingGrinder)
| | |-+  Problem with PHP + AS3 in contact form
0 Members and 2 Guests are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Problem with PHP + AS3 in contact form  (Read 5692 times)
docrgc
Server what's that
*
Posts: 3


View Profile Email
« on: 05/20/09, 07:16 »

Hello there. I have designed a contact form in Flash CS4, in conjunction with a PHP file, which should send the required data fields to an email address. When I test the SWF file containing the form, the form loads perfectly, but the instant I click on the 'Send' button, the status text 'Sending ...' appears, and stays there for ever. In addition I get the following error message:

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()[/color]

Here is my PHP file (contact.php, UTF-8 encoding)

<?php

$sendto = 'docrgc@e-mile.co.uk';
$subject = 'Laser Tokyo 2009 Registration Form'

$name = $_POST['fromname'];
$address1 = $_POST['fromaddress1'];
$address2 = $_POST['fromaddress2'];
$address3 = $_POST['fromaddress3'];
$address4 = $_POST['fromaddress4'];
$city = $_POST['fromcity'];
$state = $_POST['fromstate'];
$country = $_POST['fromcountry'];
$postcode = $_POST['frompostcode'];
$email = $_POST['fromemail'];
$number = $_POST['attendeenumber'];
$regfee = $_POST['regfeeeach'];
$feetotal = $_POST['regfeetotal'];
$ccname = $_POST['cardname'];
$cctype = $_POST['cardtype'];
$ccno = $_POST['cardnumber'];
$ccexpire = $_POST['cardexpire'];
$ccsecno = $_POST['cardsecuritynumber'];
$comewith = $_POST['accompanypersons'];

$content = "Name: " . $name . "\n\n";
$content .= "Address_1: " . $address1 . "\n";
$content .= "Address_2: " . $address2 . "\n";
$content .= "Address_3: " . $address3;
$content .= "Address_4: " . $address4 . "\n\n";
$content .= "City: " . $city . "\n";
$content .= "State: " . $state . "\n";
$content .= "Country: " . $country . "\n";
$content .= "Post_Code: " . $postcode . "\n\n";
$content .= "Email: " . $email . "\n\n";
$content .= "Reg_Persons: " . $number . "\n";
$content .= "Reg_Fee_Each: " . $regfee . "\n";
$content .= "Reg_Fee_Total: " . $regfeetotal . "\n";
$content .= "Reg_Fee_each: " . $regfee . "\n\n";
$content .= "Card_Name: " . $ccname . "\n";
$content .= "Card_Type: " . $cctype . "\n";
$content .= "Card_Number: " . $ccno . "\n";
$content .= "Card_Expires: " . $ccexpire . "\n";
$content .= "Card_Security_Number: " . $ccsecno . "\n\n";
$content .= "Accompanying_Persons" . $comewith . "\n";

if(mail($sendto,$subject,$content))
{
echo 'response=passed';
}
else
{
echo 'response=failed';
}
?>

and here is my AS3 code

send_btn.addEventListener(MouseEvent.CLICK, submit);
function submit(e:MouseEvent):void
{
var variables:URLVariables = new URLVariables();
variables.fromname = name_txt.text;
variables.fromaddress1 = address1_txt.text;
variables.fromaddress2 = address2_txt.text;
variables.fromaddress3 = address3_txt.text;
variables.fromaddress4 = address4_txt.text;
variables.fromcity = city_txt.text;
variables.fromstate = state_txt.text;
variables.fromcountry = country_txt.text;
variables.frompostcode = postCode_txt.text;
variables.fromemail = email_txt.text;
variables.attendeenumber = regPersons_txt.text;
variables.regfeeeach = regFee_txt.text;
variables.regfeetotal = regTotal_txt.text;
variables.cardname = ccName_txt.text;
variables.cardtype = ccType_txt.text;
variables.cardnumber = ccNumber_txt.text;
variables.cardexpire = ccExpire_txt.text;
variables.cardsecuritynumber = ccSecure_txt.text;
variables.accompanypersons = accompany_txt.text;

var req:URLRequest = new URLRequest("http://www.rgcbiomedical.com/LT2009/contact.php");
req.data = variables;
req.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, sent);
loader.addEventListener(IOErrorEvent.IO_ERROR, error);
loader.load(req);
status_txt.text = "Sending...";
}
function sent(e:Event):void
{
status_txt.text = "Your email has been sent.";
name_txt.text = address1_txt.text = address2_txt.text = address3_txt.text = address4_txt.text
= city_txt.text = state_txt.text = country_txt.text = postCode_txt.text = email_txt.text
= regPersons_txt.text = regFee_txt.text = regTotal_txt.text = ccName_txt.text = ccType_txt.text = ccNumber_txt.text
= ccExpire_txt.text = ccSecure_txt.text = accompany_txt.text = "";
}
function error(e:IOErrorEvent):void
{
status_txt.text = "There was an error. Please try again later.";
}

I have been through the coding of both the PHP and AS3 with a fine tooth comb. Let me say here I am an absolute novice at PHP, and picking my way gradually through the AS3 minefield. Both sets of code were adapted from a tutorial which I followed assiduously and which worked (although there were fewer fields), so I am at a loss as to why I am getting the above error message (#2101) when I test the SWF file containing the form, although it must be in my coding somewhere. I did check with the company hosting the website to make sure they were PHP compliant, and they are.
When I try sending the form actually online, after clicking on the Send button the 'Sending ...' status appears but never moves on to either the sent or the error messages. What little hair I have is fast disappearing in clumps. Any help would be greatly appreciated.
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #1 on: 05/20/09, 10:41 »

That means the PHP output is wrong, in fact you have have a syntax error on line 5: http://www.rgcbiomedical.com/LT2009/contact.php

Jorge
Logged

Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #2 on: 05/20/09, 12:33 »

The semicolon after
Code:
$subject = 'Laser Tokyo 2009 Registration Form'
is missing
Logged

happy flashing
Cool
Ronald
docrgc
Server what's that
*
Posts: 3


View Profile Email
« Reply #3 on: 05/20/09, 12:53 »

Thanks, both Jorge and Ronald, for your answers: I could not find the syntax error in Jorge's point, but the addition of that missing semicolon as per Ronald's post solved the problem: kudos galore for your much appreciated help. The form now works and the email is generated. Not all of the fields appear, but that will be my coding again, and I'll put the fields in question under the magnifying glass. Thanks again, Glen.
Logged
ProjectFlahs
Server what's that
*
Posts: 6


View Profile
« Reply #4 on: 07/06/09, 15:24 »

Alright... I'm new at this and having the same problem.  I stumbled across this and thought I found it (I forgot a semi colon as well), but unforetunately it still says Sending..., but when I debug in flash CS4 it says "Your message has not been sent. Please try again later." so it is getting a response.  Here is the two codes (I apologize for the redundancy in the AS3)

<?php



$nameInput = $_POST[‘userName’];
$emailInput = $_POST[‘userEmail’];
$phoneInput = $_POST[’userPhone’];
$addressInput = $_POST[‘userAddress’];
$cityInput = $_POST[‘userCity’];
$postalInput = $_POST[‘userPostal’];
$descriptionInput = $_POST[‘userDescription’];
 
$sender = $emailInput;
$receiver = “lars@dabpaint.ca”;
$subject = 'Quote Request';
 
$email_body = “Name: $nameInput \nEmail: $sender \nPhone: $phoneInput \naddress: $addressInput \ncity: $cityInput \npostal: $postalInput \ndescription: $descriptionInput;


 
if(mail($receiver, $subject, $email_body))
{
echo “success=yes”;
}
else
{
echo “success=no”;
}

?>

nameInput.text = addressInput.text = cityInput.text = postalInput.text =
phoneInput.text = emailInput.text = descriptionInput.text = msgStatus.text = "";

btn_send.addEventListener(MouseEvent.CLICK, submit);
btn_reset.addEventListener(MouseEvent.CLICK, reset);

stage.addEventListener(KeyboardEvent.KEY_DOWN, submit2);

var timer:Timer;
var variables:URLVariables = new URLVariables;

var varSend:URLRequest = new URLRequest("sendemail.php")
varSend.method = URLRequestMethod.POST;


var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, receive_response);


this.nameInput.tabIndex = 1;
this.addressInput.tabIndex = 2;
this.cityInput.tabIndex = 3;
this.postalInput.tabIndex = 4;
this.phoneInput.tabIndex = 5;
this.emailInput.tabIndex = 6;
this.descriptionInput.tabIndex = 7;
this.btn_send.tabIndex = 8;
this.btn_reset.tabIndex = 9;

function submit(e:MouseEvent):void
{
   if(nameInput.text=="")
   {
   msgStatus.text = "Please enter your name.";
   }
   else if(emailInput.text=="" || !validate_email(emailInput.text))
   {
      msgStatus.text = "Please enter a valid email address.";
   }
   else
   {
      msgStatus.text = "Sending...";
      // ready the variables in our form for sending
      variables.userName = nameInput.text;
      variables.userAddress = addressInput.text;      
      variables.userCity = cityInput.text;
      variables.userPostal = postalInput.text;
      variables.userPhone = phoneInput.text;      
      variables.userEmail = emailInput.text;   
      variables.userDescription = descriptionInput.text;
      
      varSend.data = variables;
      
      // Send the data to PHP now
      varLoader.load(varSend);

   }
}

function submit1()
{
   if(nameInput.text=="")
   {
   msgStatus.text = "Please enter your name.";
   }
   else if(emailInput.text=="" || !validate_email(emailInput.text))
   {
      msgStatus.text = "Please enter a valid email address.";
   }
   else
   {
      msgStatus.text = "Sending...";
      // ready the variables in our form for sending
      variables.userName = nameInput.text;
      variables.userAddress = addressInput.text;      
      variables.userCity = cityInput.text;
      variables.userPostal = postalInput.text;
      variables.userPhone = phoneInput.text;      
      variables.userEmail = emailInput.text;   
      variables.userDescription = descriptionInput.text;
      
      // Send the data to PHP now
      varLoader.load(varSend);
      
   }

}

function submit2(e:KeyboardEvent):void
{
   if (e.keyCode == Keyboard.ENTER)
    {
        submit1();
    }
}

function reset(e:MouseEvent):void
{
nameInput.text = addressInput.text = cityInput.text = postalInput.text =
phoneInput.text = emailInput.text = descriptionInput.text = msgStatus.text = "";
}

function validate_email(s:String):Boolean
{
   var indexOfAt:int;
   var lastIndexOfDot:int;
   indexOfAt = emailInput.text.indexOf("@");
   lastIndexOfDot = emailInput.text.lastIndexOf(".");
   if(indexOfAt !=-1 && lastIndexOfDot !=-1)
   {
      if(lastIndexOfDot<indexOfAt)
      {
         return false;
      }
      else
      {
         return true;
      }
   }
   else
   {
      return false;
   }
}

function receive_response(e:Event):void
{
   nameInput.text = addressInput.text = cityInput.text = postalInput.text =
phoneInput.text = emailInput.text = descriptionInput.text = msgStatus.text = "";
   
   var loader:URLLoader = URLLoader(e.target);
   var email_status = new URLVariables(loader.data).success;
   
   if(email_status =="yes")
   {
      msgStatus.text = "Thank you, your request was sent";
   }
   else
   {
      msgStatus.text = "Your message has not been sent. Please try again later."
   }
}

I'm very new to all this, any help would be appreciated!
Logged
ProjectFlahs
Server what's that
*
Posts: 6


View Profile
« Reply #5 on: 07/06/09, 15:35 »

I noticed a couple of minor mistakes in my php coding, I mirrored it to look more like docrgc's below is the new code that I am still getting stuck at Sending...

<?php

$nameInput = $_POST[‘userName’];
$emailInput = $_POST[‘userEmail’];
$phoneInput = $_POST[’userPhone’];
$addressInput = $_POST[‘userAddress’];
$cityInput = $_POST[‘userCity’];
$postalInput = $_POST[‘userPostal’];
$descriptionInput = $_POST[‘userDescription’];
 
$receiver = 'lars@dabpaint.ca';
$subject = 'Quote Request';
 
$email_body = “Name: " . $nameInput "\n";
$email_body .= "Email: " . $emailInput "\n";
$email_body .= "Phone: " . $phoneInput "\n";
$email_body .= "Address: " . $addressInput "\n";
$email_body .= "City: " . $cityInput "\n";
$email_body .= "Postal: " . $postalInput "\n";
$meail_body .= "Description: . $descriptionInput";


 
if(mail($receiver, $subject, $email_body))
{
echo “success=yes”;
}
else
{
echo “success=no”;
}

?>
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #6 on: 07/06/09, 16:04 »

Open directly the PHP in your browser and check if you get some error. If the form is online, POST the URL to take a look

Jorge
Logged

ProjectFlahs
Server what's that
*
Posts: 6


View Profile
« Reply #7 on: 07/06/09, 16:23 »

Ok... First off, if I make flash link to my actual website file I get this error

"Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///C|/Users/Lars/Desktop/Flash%20Website/www.dabpaint.ca/sendemail.php
   at DabPainting_fla::quote_15/frame1()[DabPainting_fla.quote_15::frame1:16]
   at flash.display::MovieClip/gotoAndPlay()
   at DabPainting_fla::MainTimeline/quoteClick()[DabPainting_fla.MainTimeline::frame25:66]"

If i try and open the php directly in my browser I get this error:

"Parse error: syntax error, unexpected ':' in /hermes/web03/b634/moo.larsp/sendemail.php on line 14"

This confuses me as the : is in quotes.  Does this help any diagnosis at all?

Cheers.
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #8 on: 07/06/09, 16:48 »

Lack of point for string union in almost all the lines, example:

$email_body = “Name: " . $nameInput . "\n";

Note that after $nameInput there's is a point to concat the newline character
The same for the rest of the lines. This is also the cause of the AS error

Jorge
Logged

ProjectFlahs
Server what's that
*
Posts: 6


View Profile
« Reply #9 on: 07/06/09, 18:37 »

$email_body = “Name: " . $nameInput . "\n";
$email_body .= "Email: " . $emailInput . "\n";
$email_body .= "Phone: " . $phoneInput . "\n";
$email_body .= "Address: " . $addressInput . "\n";
$email_body .= "City: " . $cityInput . "\n";
$email_body .= "Postal: " . $postalInput . "\n";
$email_body .= "Description: . $descriptionInput";

Here's the new code, still have the same syntax error on the the line 14 (first line above).  Would have been an error though for not concating properly, so thanks for that Jorge.  Any other Ideas?

"Parse error: syntax error, unexpected ':' in /hermes/web03/b634/moo.larsp/sendemail.php on line 14"
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #10 on: 07/07/09, 00:42 »

check the first qoute - it looks weird, so might not be interpreted as quote - therfor the colon will not be inside of a string Wink
Logged

happy flashing
Cool
Ronald
ProjectFlahs
Server what's that
*
Posts: 6


View Profile
« Reply #11 on: 07/07/09, 01:33 »

Alright, thanks again for your replies.  Ronald, you were 100% right: my keyboard has a funky thing that sometimes changes languages on me.  I wish I read this posting before i fiddled with it for an hour and finally removed the line and retyped it.  So it emails me now, but all i get is blank fields.  Maybe an error in my AS3 code?  I can't believe how long I've spent on such a simple task (last thing to complete my website).  Any more help would be greatly appreciated.  I've tried manipulating a few things on my AS3 code, but no luck.  It seems very similar to docrgc... Don't know what I could be doing wrong.  cheers.
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #12 on: 07/07/09, 05:46 »

maybe it is a mistyped variables name or alike Wink

use charles to findout what happens on the line.
Then you know if it is the sender or receiver causing the trouble.
Logged

happy flashing
Cool
Ronald
ProjectFlahs
Server what's that
*
Posts: 6


View Profile
« Reply #13 on: 07/07/09, 12:16 »

Whew.... Thanks for all your help guys.  You won't believe what was wrong.  Ronald, after you noticed the strange quote, I got to thinking other things might be strange too.  I copied and pasted from docrgc's code the ' s and it worked.  That wasted enough time that I fixed my keyboard changing language problem.  By the way, Charles is a fantastic program (let me know it was the php code and that the variables were passed correctly from flash).  My website is now fully functional!
Logged
AudreyGentry
Server what's that
*
Posts: 1

AudreyGentry AudreyGentry
View Profile Email
« Reply #14 on: 07/15/11, 05:27 »

I  had  same problem. But your post solve my problem. Thanks for sharing.
Logged

Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!