flash as3 php contact form help
The flash isnt talking to php. I hope someone can see the changes I need to make to fix it. Thanks in advance.
Here is my php code:
Code:
<?php
/************************************************************
mailform.php
*************************************************************/
$recipient = "[email protected]";
$subject = "Automail";
//variables from swf
$name = $_POST['textName'];
$email = $_POST['textEmail'];
$message = $_POST['textMessage'];
$results= $_POST['textResults'];
$mail = "Contact from $name email $email
has left the following message: $message ";
mail($recipient, $subject, $message, "From: $name");
print &results="Data Sent... Thank You.";
?>
here is my flash code:
Code:
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("mailform.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
stop();
//sets focus to the Name text box
stage.focus = name_txt;
//method to submit form
submit_btn.addEventListener(MouseEvent.CLICK, sendData);
//function called from method, contains validation logic and var data to be sent to form
function sendData(event:MouseEvent):void{
//validate form fields
if(!name_txt.length) {
results_txt.text = "Please enter your name.";
} else if(!email_txt.length) {
results_txt.text = "Please enter an email address";
}else if(!validateEmail(email_txt.text)) {
results_txt.text = "Please enter a VALID email address";
} else if(message_txt.length <= 1) {
results_txt.text = "Please enter a message.";
} else {
results_txt.text = "Sending...";
//sends the text box variables to mailform.php by calling the varSend method
//these lines are commented out for testing purposes
variables.textName = name_txt.text;
variables.textEmail = email_txt.text;
variables.textMessage = message_txt.text;
variables.textResults = results_txt.text;
varLoader.load(varSend);
trace("Email: "+email_txt.text);
trace("Text length: "+message_txt.length);
trace("Valid email: "+validateEmail(email_txt.text));
trace("Message: "+message_txt.text);
trace("Form validated");
//moves mc timeline to frame 2
//gotoAndStop(2);
}
}