I have made a Flash AS3 / PHP form. The form works perfectly!
Now I would like to make it so if the Name and Email fields are not filled out then the form will not send and display the text “Required form field”. I am not sure how to go about doing this. Do I just need to add code in flash or in PHP as well.
Can someone please help!!!
Flash Code:
send_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.senderSubject = subject_txt.text;
my_vars.senderMsg = message_txt.text;
var my_url:URLRequest = new URLRequest("mail2.php");
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
//my_loader.dataFormat = URLLoaderDataFormat.TEXT;
my_loader.load(my_url);
my_loader.addEventListener(Event.COMPLETE, startListener);
function startListener (e:Event):void{
trace("Loading Completed");
MovieClip(root).nextFrame();
}
}
clear_btn.addEventListener(MouseEvent.CLICK, reset);
function reset(e:MouseEvent):void {
name_txt.text = "";
email_txt.text = "";
subject_txt.text = "";
message_txt.text = "";
}
PHP code:
<?php$to = "myemail@mydomain.com";$subject = "Website Contact Form Response";$message = ($_POST['senderMsg']);$message .= "
---------------------------
";$message .= "E-mail Sent From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . ">
Subject: " . $_POST['senderSubject'] . "
";$headers = "From: " . $_POST['senderName'] . " <" . $_POST['senderEmail'] . "><" . $_POST['senderSubject'] . ">
";if(@mail($to, $subject, $message, $headers)){echo "answer=ok";} else {echo "answer=error";}?>