contact form functionality
Hello there,
Ok so here's my problem. I have almost completed my website with all the buttons and MC's communicating nicely with their respective frames. I am on my final frame being the "Contact Form" frame. I searched the web to find a tutorial in finding as3 contact form.
Link: http://www.republicofcode.com/tutorials/flash/as3contactform
It was easy to follow and helpful. I created a php file called "mail.php" and an .fla file called "contactmovie.fla".
I followed the steps and finally put in the required as3 in the contactmovie.fla. I tested contactmovie.fla in a browser effectively creating an swf file in the same name. In the browser, I typed into the text fields and pressed submit which returned a "Message Sent" response. All appears well.
BUT...
When I want to incorporate this into a website that I am creating in flash under a different file name I have issues.
1. I am not sure whether I need to import the contactmovie.swf file into the website .fla file which I called allrounda.fla (also, when I do this no text appears); or,
2. I can simply copy the frames in the contactmovie.fla file and paste the frames into the allrounda.fla file.
Eitherway, doesn't seem to work. In point 2, the text is displayed but when I type the details in the text field, no "Message Sent" is displayed.
This indicates to me that the script is not communicating with the text fields which has the instance names of name_txt, email_txt and message_txt. The instance names do correspond to the script. The contact form created is not on frame 1 but frame 5. There is an MC that behaves like a button that takes you to frame 5 where the contact form is on.
It is probably a small issue with an as3 guru.
AS3 SCRIPT
//CONTACT FORM //
submit_btn.addEventListener(MouseEvent.CLICK, sendMessage);
function sendMessage(e:MouseEvent):void{
var my_vars:URLVariables = new URLVariables();
my_vars.senderName = name_txt.text;
my_vars.senderEmail = email_txt.text;
my_vars.senderMsg = message_txt.text;
var my_url:URLRequest = new URLRequest("allrounda.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);
name_txt.text = "";
email_txt.text = "";
message_txt.text = "Message Sent";
}
PHP SCRIPT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$to = "dalipagic@gmail.com";
$subject = ($_POST['senderName']);
$message = ($_POST['senderMsg']);
$message .= "\n\n---------------------------\n";
$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">\n";
if(@mail($to, $subject, $message, $headers))
{
echo "answer=ok";
}
else
{
echo "answer=error";
}
?>
</body>
</html>
/////////////////////////////////////
Or is it the case that this will all work when I have uploaded both .fla and .php file to the server?
I know it is a lot to ask but it would be appreciated.
Kind regards,
Dean D