Thursday, July 31, 2008

Flash - PHP Feedback Form

Flash - PHP Feedback Form. It is easy to create and send your comments with in few seconds..













Paste below codings in your flash action script file.





var sendData_lv:LoadVars = new LoadVars();

var receiveData_lv:LoadVars = new LoadVars();

var formValidated:Boolean;

var errorMessages:Array = new Array();



receiveData_lv.onLoad = function():Void{

trace(this.sent);

if(this.sent == "OK"){

message0_txt.text = "Thank you for your feedback";

}else{

message0_txt.text = this.sent;

}

}





submit_btn.onRelease = function() {

//this clears the error text field if they have been populate previously

clearTextFields();

errorMessages.length = 0; //empty the array so next time the submit button is clicked the array is not already populated

formValidated = checkForm();

if (formValidated) {

//the form is valid and so now we can send details to our PHP file

//populate LoadVars object with the field values

sendData_lv.name = name_txt.text;

sendData_lv.email = email_txt.text;

sendData_lv.feedback = feedback_txt.text;

//trace(sendData_lv.email);

//trace("valid");

sendData_lv.sendAndLoad("email.php?ck="+new Date().getTime(), receiveData_lv);

} else {

//populate textfields with the error messages

for (var i = 0; i
_root["message"+i+"_txt"].text = errorMessages[i];

trace(errorMessages[i]);

}

}

};





function checkForm():Boolean {

//check whether the name field is empty

if (name_txt.text == "") {

errorMessages.push("Please enter your name.");

}

if (email_txt.text == "") {

errorMessages.push("Please enter your email address.");

} else if (email_txt.text.indexOf("@") == -1 || email_txt.text.indexOf(".") == -1) {

errorMessages.push("Please enter a valid email address.");

}

if (feedback_txt.text == "") {

errorMessages.push("Please enter some feedback");

}

//if at this point the array is empty i.e has length 0, then this in effect means the form has passed all checks

if (errorMessages.length == 0) {

return true;

} else {

return false;

}

}





function clearTextFields():Void {

for (var i = 0; i
_root["message"+i+"_txt"].text = "";

;

}

}





Your Actionscript file is ready then create a phpl file to send your information. The php file names as email.php




$name = $_POST['name'];

$email = $_POST['email'];

$feedback = $_POST['feedback'];

$subject = 'feedback from your website';

$headers = "From: $name <$email>\n";

$headers .= "Reply-To: $name <$email>\n";



//ENTER YOUR EMAIL ADDRESS HERE

$to = 'innovativeidea@gmail.com';

//---------------------------



$success = mail($to, $subject, $feedback, $headers);

if($success){

echo '&sent=OK';

}else{

echo '&sent=Error';

}

?>





 













No comments:

Post a Comment