-
Flash + Php Mailer
Hello!
I got my form to work and all the variables show up in my email. Sweet! The only problem that I'm having now is with the validation. I've placed an alert on the form if its incomplete. The alert doesn't show up and the form doesn't go to the next frame if accordingly. Please help!
I think the problem lies between my php code and AS2 code not communicating. Sorry for all the code!
AS2 code:
Code:
stop();
import mx.controls.Alert;
//mx.accessibility.NumericStepperAccImpl.enableAccessibility();
_global.style.setStyle("themeColor", "haloBlue");
//var firstName:String = "";
//var lastName:String = "";
//var phone:String = "";
//var eMail:String = "";
var eventType:String = "";
//var eventOther:String = "";
//var hearCompany:String = "";
//var hearOther:String = "";
var eventDate:String = "";
//var time:String = "";
//var location:String = "";
//var numGuests:String = "";
//var budget:String = "";
var servicesNeeded:String = "";
//var comments:String = "";
firstname_txt.restrict = "A-Z a-z";
lastname_txt.restrict = "A-Z a-z";
phone_txt.restrict = "-0123456789";
email_txt.restrict = "a-z@._-01234567890";
clock.restrict = ":01234567890ampmAMPM.";
place.restrict = "A-Z a-z.,";
budget_txt.restrict = ",0-9.,";
other_txt.restrict = "A-Z a-z";
other_txt2.restrict = "A-Z a-z";
comm.restrict = "A-Z a-z@.!?_-01234567890";
firstname_txt.tabIndex = 1;
lastname_txt.tabIndex = 2;
phone_txt.tabIndex = 3;
email_txt.tabIndex = 4;
eventType_cb.tabIndex = 5;
other.tabIndex = 6;
company_cb.tabIndex = 7;
others.tabIndex = 8;
calendar.tabIndex = 9;
clock.tabIndex = 10;
place.tabIndex = 11;
NumbericStepper.tabIndex = 12;
budget_txt.tabIndex = 13;
services.tabIndex = 14;
comm.tabIndex = 15;
Selection.setFocus(firstname_txt);
arrivalDateListener = new Object();
arrivalDateListener.change = function(eventObj) {
var eventSource = eventObj.target;
var theSelectedDate = eventSource.selectedDate;
// format the date
var theDate = theSelectedDate.getDate();
var theMonth = theSelectedDate.getMonth()+1;
var theYear = theSelectedDate.getFullYear();
var formattedDate = theMonth+"/"+theDate+"/"+theYear;
eventDate = formattedDate;
};
calendar.addEventListener("change", arrivalDateListener);
/*var listListener:Object = new Object();
listListener.change = function(evt_obj:Object) {
servicesNeeded = servicesNeeded += services.selectedItem.label;
trace(servicesNeeded);
trace("You have selected " + services.selectedItems.length + " items.");
}
services.addEventListener("change", listListener);
*/
submit_btn.onRelease=function () {
/*trace(firstname_txt.text);
trace(lastname_txt.text);
trace(guests.value);
trace(phone_txt.text);
trace(email_txt.text);
trace(eventType_cb.selectedItem.label);
trace(company_cb.selectedItem.label);
trace(eventDate);
trace(time_txt.text);
trace(location_txt.text);
trace(budget_txt.text);
trace(services.selectedItem.label);*/
var sendLoad:LoadVars = new LoadVars();
var receiveLoad:LoadVars = new LoadVars();
if (other.text==""){
sendLoad.other=" ";
}else{
sendLoad.other=other.text;
}
if (others.text=="") {
sendLoad.others=" ";
}else{
sendLoad.others=others.text;
}
if (comm.text==""){
sendLoad.comm=" ";
}else{
sendLoad.comm=comm.text;
}
if (firstname_txt.text=="") {
firstDynamic.textColor = "0xFF0000";
firstDynamic.text = "First Name:";
}else{
firstDynamic.textColor = "0x273F63";
firstDynamic.text = "First Name:";
sendLoad.firstname=firstname_txt.text;
}
if (lastname_txt.text==""){
lastDynamic.textColor="0xFF0000";
lastDynamic.text="Last Name:";
}else{
lastDynamic.textColor="0x273F63";
lastDynamic.text="Last Name:";
sendLoad.lastname=lastname_txt.text;
}
if (phone_txt.length<=10){
telephoneDynamic.textColor="0xFF0000";
telephoneDynamic.text="Telephone:";
}else{
telephoneDynamic.textColor="0x273F63";
telephoneDynamic.text="Telephone:";
sendLoad.phone=phone_txt.text;
}
if(email_txt.text==""){
emailDynamic.textColor="0xFF0000";
emailDynamic.text="Email:";
}else{
emailDynamic.textColor="0x273F63";
emailDynamic.text="Email:";
sendLoad.email=email_txt.text;
}
if(eventType_cb.text==""){
eventsDynamic.textColor="0xFF0000";
eventsDynamic.text="Type of Event:";
}else{
eventsDynamic.textColor="0x273F63";
eventsDynamic.text="Type of Event:";
sendLoad.eventType=eventType_cb.selectedItem.label;
}
if(company_cb.text==""){
companyDynamic.textColor="0xFF0000";
companyDynamic.text="How did you hear about the company?";
}else{
companyDynamic.textColor="0x273F63";
companyDynamic.text="How did you hear about the company?";
sendLoad.hearCompany=company_cb.selectedItem.label;
}
if(calendar.text==""){
dateDynamic.textColor="0xFF0000";
dateDynamic.text="Date:";
}else{
dateDynamic.textColor="0x273F63";
dateDynamic.text="Date:";
sendLoad.calendar=eventDate;
}
if(clock.text==""){
timeDynamic.textColor="0xFF0000";
timeDynamic.text="Time:";
}else{
timeDynamic.textColor="0x273F63";
timeDynamic.text="Time:";
sendLoad.clock=clock.text;
}
if(place.text==""){
locationDynamic.textColor="0xFF0000";
locationDynamic.text="Location:";
}else{
locationDynamic.textColor="0x273F63";
locationDynamic.text="Location:";
sendLoad.place=place.text;
}
if(guests.text==""){
guestsDynamic.textColor="0xFF0000";
guestsDynamic.text="How many guests?:";
}else{
guestsDynamic.textColor="0x273F63";
guestsDynamic.text="How many guests?:";
sendLoad.guests=guests_ns.value;
}
if(budget_txt.text==""){
budgetDynamic.textColor="0xFF0000";
budgetDynamic.text="What's your budget?:";
}else{
budgetDynamic.textColor="0x273F63";
budgetDynamic.text="What's your budget?:";
sendLoad.budget=budget_txt.text;
}
if(services.selectedItems.length <=0){
servicesDynamic.textColor="0xFF0000";
servicesDynamic.text="Services Needed:";
}else{
servicesDynamic.textColor="0x273F63";
servicesDynamic.text="Services Needed:";
var numSelected:Number = services.selectedIndices.length;
for (var i:Number = 0; i < numSelected; i++) {
//trace("selectedIndices[" + i + "] = "+ services.getItemAt(services.selectedIndices[i]).label);
servicesNeeded += String(services.getItemAt(services.selectedIndices[i]).label)+"\n";
}
//trace(servicesNeeded);
sendLoad.services=servicesNeeded;
}
//trace(sendLoad.toString());
sendLoad.sendAndLoad("sendMailDH.php",receiveLoad,"POST");
receiveLoad.onLoad = function(success:Boolean) {
if (success) {
if(receiveLoad.answer=="sent"){
gotoAndPlay(2);
}else{
Alert.show("The form is incomplete, please fill in the highlighted areas!", "Warning!");
}
received1Txt.text = receiveLoad.answer;
}else{
//trace
Alert.show("There was a problem with the server. Please try again.", "Server Error");
}
}
}
function clearContactForm(){
firstname_txt.text = "";
lastname_txt.text = "";
phone_txt.text = "";
email_txt.text = "";
eventType_cb.selectedIndex = 0;
other.text = "";
company_cb.selectedIndex = 0;
others.text = "";
calendar.text ="";
clock.text = "";
place.text = "";
guests.selectedIndex = 0;
budget_txt.text = "";
services.selectedIndexs = 0;
comm.text = "";
}
Php Code:
PHP Code:
<?php
if(!empty($_POST['firstname'])
|| !empty($_POST['lastname'])
|| !empty($_POST['phone'])
|| !empty($_POST['email'])
|| !empty($_POST['eventType'])
|| !empty($_POST['hearCompany'])
|| !empty($_POST['calendar'])
|| !empty($_POST['clock'])
|| !empty($_POST['place'])
|| !empty($_POST['guests'])
|| !empty($_POST['budget'])
|| !empty($_POST['services'])
|| !empty($_POST['comm'])
|| !empty($_POST['other'])
|| !empty($_POST['others'])
{
// Every variable in a nice little array.
// Don't use name, message or state. These names are already defined in Actionscript. Be unique.
$data = array('firstname_txt' => $_POST['firstname'], 'lastname_txt' => $_POST['lastname'], 'phone_txt' => $_POST['phone'], 'email_txt' => $_POST['email'], 'eventType_cb' => $_POST['eventType'], 'company_cb' => $_POST['hearCompany'], 'calendar' => $_POST['calendar'], 'clock' => $_POST['clock'], 'place' => $_POST['place'], 'guests' => $_POST['guests'], 'budget_txt' => $_POST['budget'], 'services' => $_POST['services'], 'comm' => $_POST['comm'], 'other' => $_POST['other'], 'others' => $_POST['others']);
// Who should the email go to?
$to = "rgipson1@hotmail.com";
// What's the general subject?
$subject = "Event Planning By Ebony";
// To send HTML mail, the Content-type header must be set.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = 'From: ' . $data['firstname_txt'] . ' (' . $data['email_txt'] . ')' . "\r";
// Our final message:
$message = 'First Name:' . $data['firstname_txt'] . "\r\n";
$message .= 'Last Name:' . $data['lastname_txt'] . "\r\n";
$message .= 'Telephone:' . $data['phone_txt'] . "\r\n";
$message .= 'Email:' . $data['email_txt'] . "\r\n";
$message .= 'Type of Event:' . $data['eventType_cb'] . "\r\n";
$message .= 'How did you hear about the company?:' . $data['company_cb'] . "\r\n";
$message .= 'Date:' . $data['calendar'] . "\r\n";
$message .= 'Time:' . $data['clock'] . "\r\n";
$message .= 'Location:' . $data['place'] . "\r\n";
$message .= 'How many guests?:' . $data['guests'] . "\r\n";
$message .= 'Budget:' . $data['budget_txt'] . "\r\n";
$message .= 'Services Needed:' . $data['services'] . "\r\n";
$message .= 'Comments:' . $data['comm'] . "\r\n";
$message .= 'Other:' . $data['other'] . "\r\n";
$message .= 'Other:' . $data['others'] . "\r\n";
$message .= stripslashes($data['comm']) ."\r\n";
$message .= 'You can reply to this message by contacting ' . $data['firstname_txt'] . ' at: ' .$data['email_txt'] . "\r";
// Email that son of a gun!
mail($to, $subject, $message, $headers);
echo "answer=sent";
}else{
echo "answer=error";
}
?>
-
FK'n_dog
List Variables to see if receiveLoad.answer includes any linebreaks - sent\r\n
if so, enclose the var/value pair with ampersands
echo "&answer=sent&";
-
Hi,
your php code says that the mail is sent if ANY of the variables is not empty - wouldn't it make more sense to require that ALL (or at least a group of) variables are filled?
Beware of putting user-supplied data (first name and email address) into headers
Musicman
-
Flash + Php Mailer
Yes, it would make sense to do it that way. I'm really new to this coding with php. I just need to make the validation work and I'm home free. Otherwise, it just works and you can submit the form without any info being supplied and no alert that says incomplete form. Or I could just disable the submit button until all fields are populated. I really don't want to go that route. I'm so close to getting this right. If anyone could help I would greatly appreciate it.
-
Hi,
just replace these || with && to change the logic.
Another thought - are all of these fields really needed?
Musicman
-
Flash + Php Mailer
Thank you for your help! Yes, I need all of the fields. I will try your recommendations and let you know the results.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|