Hiya,
I need some assistance on this project. I'm to create a series of contact form ad banners. I have a great little contact form, but I am a novice when it comes to ActionScript. The form uses POST and an outside php page to process the emailing of each contact submission. However, I need to change the code below to Yahoo specs: http://adspecs.yahoo.com/content/as3_tutorial.html
There are a series of form checks happening here, but here is the block of code I believe I need to adjust:
if(passChecks) {
submit_btn.enabled = false;
feedback_mc.visible = true;
feedback_mc.gotoAndStop(SENDING);
var urlVars:URLVariables = new URLVariables();
var urlReq:URLRequest = new URLRequest("send_email.php");
var ldr:URLLoader = new URLLoader();
urlVars.name = name_txt.text;
urlVars.email = email_txt.text;
urlVars.message = message_txt.text;
urlReq.data = urlVars;
urlReq.method = URLRequestMethod.POST;
ldr.addEventListener(Event.COMPLETE, serverFeedback);
ldr.load(urlReq);
}
So, instead of URLRequestMethod.POST it needs to be GET (per Yahoo/Google specs). And then instead of URLRequest("send_email.php"); I need to append the variables to "clickTAG".
There is also some communication between the "send_email.php" file and the swf, which doesn't need to happen. See full block of code below.
I'd be more than happy to discuss this over email rocketmunkee (at) yahoo (dot) com. And I'll be happy to post the solution here, as well. Please advise. I'm stumped and ready to take up basketweaving.
Jonathan
import fl.managers.StyleManager;
StyleManager.setStyle("textFormat", new TextFormat("Verdana", 11, 0x000000));
const SENDING:String = "Sending";
const SENT_SUCCESS:String = "Successful";
const SENT_FAILED:String = "Unsuccessful";
var tmr:Timer;
function resetTextFields():void {
name_txt.text = "";
email_txt.text = "";
message_txt.text = "";
}
function resetContactForm():void {
submit_btn.enabled = true;
feedback_mc.visible = false;
clearErrors();
}
function afterTmrWait(evt:TimerEvent):void {
tmr.stop();
tmr.removeEventListener(TimerEvent.TIMER, afterTmrWait);
resetContactForm();
}
// From AS3 Doc.
function validateEmail(str:String):Boolean {
var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var result:Object = pattern.exec(str);
if(result == null) {
return false;
}
return true;
}
function submitForm(evt:MouseEvent):void {
clearErrors();
var passChecks:Boolean = true;
if(name_txt.text.length < 1) {
nameError_mc.visible = true;
passChecks = false;
}
if(!validateEmail(email_txt.text)) {
emailError_mc.visible = true;
passChecks = false;
}
if(message_txt.text.length < 1) {
messageError_mc.visible = true;
passChecks = false;
}
if(passChecks) {
submit_btn.enabled = false;
feedback_mc.visible = true;
feedback_mc.gotoAndStop(SENDING);
var urlVars:URLVariables = new URLVariables();
var urlReq:URLRequest = new URLRequest("send_email.php");
var ldr:URLLoader = new URLLoader();
urlVars.name = name_txt.text;
urlVars.email = email_txt.text;
urlVars.message = message_txt.text;
urlReq.data = urlVars;
urlReq.method = URLRequestMethod.POST;
ldr.addEventListener(Event.COMPLETE, serverFeedback);
ldr.load(urlReq);
}
}
function serverFeedback(evt:Event):void {
var ldr:URLLoader = evt.target as URLLoader;
var urlVars:URLVariables = new URLVariables(ldr.data);
if(urlVars.result == SENT_SUCCESS) {
feedback_mc.gotoAndStop(SENT_SUCCESS);
resetTextFields();
} else if(urlVars.result == SENT_FAILED) {
feedback_mc.gotoAndStop(SENT_FAILED);
}
tmr = new Timer(3000, 1);
tmr.addEventListener(TimerEvent.TIMER, afterTmrWait);
tmr.start();
}
function clearErrors():void {
nameError_mc.visible = false;
emailError_mc.visible = false;
messageError_mc.visible = false;
}
submit_btn.addEventListener(MouseEvent.CLICK, submitForm);
resetTextFields();
resetContactForm();
North America
Europe, Middle East and Africa
Asia Pacific