Skip to main content
Participating Frequently
August 11, 2008
Question

Flash email form

  • August 11, 2008
  • 7 replies
  • 1957 views
I am working on an email form on Flash and I got most of it done. However theres a small mistake that I cant seem to find.

*Heres my actionscript (please check the "if" part since the problem is there):

stop();

var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();

sender.onRelease = function() {
senderLoad.Name = Name.text;
senderLoad.Email = Email.text;
senderLoad.Phone = Phone.text;
senderLoad.Message = Message.text;
senderLoad.sendAndLoad
(" http://mainlinejerky.com/index/mainlinemail.php",receiveLoad);
}

receiveLoad.onLoad = function() {
if(this.sentOk) {
_root.gotoAndStop("success");
}
else {
_root.gotoAndStop("failed");
}
}


*heres my PHP:

<?php

$to = "mm_slider2001@yahoo.com";
$subject = "Mainline Jerky Order";

$headers = "From: $Email";
$headers .= "\nReply-To: $Email";

$message = "Name: " . $Name;
$message .= "\nEmail: " . $Email;
$message .= "\n\nPhone: " . $Phone;
$message .= "\n\n\nMessage: " . $Message;


$sentOk = mail($to, $subject, $message, $headers);

echo "sentOk=" . $sentOk;


?>


MY problem is that even when the fields are empty, one can still submit the form without playing my
"failed" message.

What do I need to do? What can I add to the actionscript to play my "failed" message when a field is empty?


Thanks in advanced! Hope the info provided is helpful!
This topic has been closed for replies.

7 replies

Mendo08Author
Participating Frequently
August 17, 2008
ok heres what i did, just to see that I wasnt crazy. I uploaded you swf and your PHP into my server and the flash form is in my contact pg. The only change was the path of the php file in the actionscript. everything else is the same when I got the zip file from you. check it:

http://mainlinejerky.com/email_pg.html

and it ONLY works when I exported from flash but it wont work after uploading it into my server. Same thing with my version. Go ahead and try it.

in my actionscript i typed:
http://www.mainlinejerky.com/index/mainlineEmail.php

since thats the location of the script. Its under the "index" folder in my server. So what would be the correct way to describe the location or "Path" of the PHP? feel free to use the form.

Thanks for your time!!
August 18, 2008
I noticed you have placed a lot of content in this "index" folder (viewing your page source). Did you create this folder? It's obviously not the root of your web server because the index.html page of http://mainlinejerky.com/index.html is at the root of your server. I see that email_pg.html is at the root which holds the swf file at index/mainlineEmail.swf. You said you placed the php script at the same level as the swf index/mainlineEmail.php.

In the distant past, I've come across some servers where the php scripts will ONLY work at the root level of the server. Because of that possibility, I always place my swf files and script files at the root level of my clients' server. You can test this out by uploading the swf file and php script to the root of your web server (same area where index.html lies). If you notice my example I sent a few posts ago, I had several folder levels to that script -

"flash/mainlineEmail/mainlineEmail.php" - the swf file is at the same level. So, by placing those 2 files at the root of your server will be a good test. If things worked (my example) when you exported from Flash but not when you uploaded, try switching the absolute path to a relative one. Actually, try this first before you upload the php file and swf to the root of your server. So, your sendAndLoad would point to "mainlineEmail.php" - if that doesn't change anything, try the other suggestion of uploading to the root of your web server.

So, to clear things up, try:

1. change your absolute path to a relative one, publish flash file, re-upload the swf file to index/mainlineEmail.swf - test it
2. upload mainlineEmail.swf and mainlineEmail.php to the root of your web server - test it

If neither one of those pass, there may be something else in your flash file that's causing the conflict. I can help a lot faster if I can see the flash file and the php script you are currently using.
Mendo08Author
Participating Frequently
August 18, 2008
Hey friend!
Your tip worked!!! Oh man I finally got it to work right! I never thought this would be so hard to figure out! Man thank you sooooo very much for your time. I guess actionscript and php isnt as easy to understand as it looked.

Again you are a SAVIOR!!!

God Bless you!!
August 17, 2008
Your script seems to have changed a couple of times in this post, so I would have to know the particular problem you were having compared to the script you were using at that time. I think it's just easier to look at what I did, compare it yours, and notice the differences.

"I uploaded my php script (which is actually what you wrote but now modified to fit my form) but I dont know what the appropriate way to upload it is. Do you have yours in folders or what?" - Just make sure the path to the php script in your action script reflects the path to the file on your server. I always place the php file in the same folder as my swf file (which are always placed under the root folder of the web server). You can place the php file in a different folder than your swf file - just make sure you have the correct path in your script. I always use absolute paths in my script when it comes to connecting to files other than swf files (my choice).

It's possible you have a "scope" problem with your variables. If you are trying passing empty or undefined variables, the php script will fail. Comment out the sendAndLoad line of script (place "//" in front of the script) and add a trace:

trace (Name.text+newline+Email.text+newline+Phone.text+newline+Message.text);

Test that in Flash to see if it traces the same values as when you fill out the form. How do you know it's not sending the email (other than you not receiving it)? Are you testing this by putting your email address in the Email field?

If you are still having trouble, I will need to see your fla file and your edited php file to help further.
kglad
Community Expert
Community Expert
August 16, 2008
i don't see anything wrong with the code you posted. but you should be using a relative path to your php file because your hosting company may have restrictions on what could appear to be an outside call to an executable file and you should use the receiveLoad.onData(src) and view the returned src parameter. the latter may show error messages being generated.
Mendo08Author
Participating Frequently
August 16, 2008
what would you consider to be a "relative path"?

and is th this what you mean for "onData"?

receiveLoad.onData = function() {
if(this.sentOk = "true") {
_root.gotoAndStop("success");

Please show me on the code cuz it seemed like I understood this but its like I dont quite get it anymore!

I'll contact my hosting company askin them about my php. file


thanks!
kglad
Community Expert
Community Expert
August 16, 2008
if you have flash tracer installed you can use:

sbryner
Inspiring
August 13, 2008
What if you checked it before you sent it like this?

sender.onRelease = function() {
senderLoad.Name = Name.text;
senderLoad.Email = Email.text;
senderLoad.Phone = Phone.text;
senderLoad.Message = Message.text;

if(senderLoad.Name==""||senderLoad.Email==""||senderLoad.Phone==""||senderLoad.Message"){
// throw up an alert box
}else{
senderLoad.sendAndLoad
(" http://mainlinejerky.com/index/mainlinemail.php",receiveLoad);
}
};
Mendo08Author
Participating Frequently
August 14, 2008
Ok heres what I got so far. It worked for a while at first but now its not sending the emails.

actionscript:
stop();

var senderLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();

sender.onRelease = function() {
senderLoad.Name = Name.text;
senderLoad.Email = Email.text;
senderLoad.Phone = Phone.text;
senderLoad.Message = Message.text;

if(senderLoad.Name==""||senderLoad.Email==""||senderLoad.Phone==""||senderLoad.Message=="") {
_root.gotoAndStop("failed")

}
else{
senderLoad.sendAndLoad(" http://mainlinejerky.com/index/mainlinemail.php", receiveLoad, "POST");
}
};


receiveLoad.onLoad = function() {
if(this.sentOk = "true") {
_root.gotoAndStop("success");
}
else {
_root.gotoAndStop("failed");
}
}

PHP:

<?php

$to = "mm_slider2001@yahoo.com";
$subject = "Mainline Jerky Order";

$headers = "From: $Email";
$headers .= "\nReply-To: $Email";

$message = "Name: " . $Name;
$message .= "\nEmail: " . $Email;
$message .= "\n\nPhone: " . $Phone;
$message .= "\n\n\nMessage: " . $Message;

$sentOk = mail($to, $subject, $headers, $message);

echo "sentOk = true" . $sentOk;


?>


The "success" and "failed" play but now the emails ARE NOT being sent! It did work for a bit but then it stopped sending emails.

Did I mess up somewhere? Or do I need to add something to the button. Please help!!
kglad
Community Expert
Community Expert
August 14, 2008
:

kglad
Community Expert
Community Expert
August 13, 2008
change your php script to:

echo "sentOk=true";
kglad
Community Expert
Community Expert
August 12, 2008
compare this.sentOk with "true".
Mendo08Author
Participating Frequently
August 12, 2008
Sorry but I dont have a lot of actionscript knowledge.

How do I "compare" them? is it like this [this.sentOk=true]
You think you can show me on the code? One thing I want is for the "Failed" message to play
if one or all fields are empty.

Im reading some stuff on actionscript but im still not understanding it well yet. Please help . I dont have many references to use.



kglad
Community Expert
Community Expert
August 12, 2008
:

kglad
Community Expert
Community Expert
August 11, 2008
this.sentOk is a string, not a boolean.
Mendo08Author
Participating Frequently
August 11, 2008
Ok so what do I do?

Do I add the Boolean? I saw a video that showed me how to do this code so Im not sure what happened. If you need to see the actual form heres the link:

http://mainlinejerky.com/email_pg.html

Dont use th form yet!