Jump to content

Recommended Posts

so i've been building out this form in flash cs4 and i can't for the life of me get the checkboxes to submit their labels to the php mailer please help!!! thanks.

 

here's the AS3:

// Function to populate gas type
function addGasTypesToList ():void {
userFuel.addItem( {label: "Fuel Interests"} );
userFuel.addItem( {label: "E85"} );
userFuel.addItem( {label: "BioDiesel"} );
userFuel.addItem( {label: "EV Charging"} );
userFuel.addItem( {label: "ALL"} );
}
//Run function above now
addGasTypesToList ();



var variables:URLVariables = new URLVariables;

//Build the varSend variable
var varSend:URLRequest = new URLRequest("form_parse.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;

//Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);

//handler for the PHP script completion and return of status
function completeHandler(event:Event):void{
//remove processing clip
userName.text = "";
userEmail.text = "";
userPhone.text = "";
userCompany.text = "";
userAddress.text = "";
userCity.text = "";
userState.text = "";
userZip.text = "";
userVehicle.text = "";
userMessage.text = "";
subjectNews.selected = false;
subjectBrochure.selected = false;
subjectStation.selected = false;
subjectSelling.selected = false;
subjectFleet.selected = false;
subjectPress.selected = false;
subjectCorporate.selected = false;
subjectOther.selected = false;
//Load the response from PHP here
messageStatus.text = event.target.data.return_msg
}



// Add event listener for submit button click
sendButton.addEventListener(MouseEvent.CLICK, ValidateAndSend);

//function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void{

//validate fields
if(!userName.length) {
	messageStatus.text = "Please enter your name";
}else if( !validate_email(userEmail.text) ) {
	messageStatus.text = "Please enter a VALID email";
}else {

	//All is good, send the data to PHP
	messageStatus.text = "sending...";

	//ready the variables for sending
	variables.userName = userName.text;
	variables.userEmail = userEmail.text;
	variables.userPhone = userPhone.text;
	variables.userCompany = userCompany.text;
	variables.userAddress = userAddress.text;
	variables.userCity = userCity.text;
	variables.userState = userState.text;
	variables.userZip = userZip.text;
	variables.userVehicle = userVehicle.text;
	variables.userFuel = userFuel.value;
	variables.userMessage = userMessage.text;
	variables.userNews = subjectNews.selected;
	variables.userBrochure = subjectBrochure.selected;
	variables.userStation = subjectStation.selected;
	variables.userSelling = subjectSelling.selected;
	variables.userFleet = subjectFleet.selected;
	variables.userPress = subjectPress.selected;
	variables.userCorporate = subjectCorporate.selected;
	variables.userOther = subjectOther.selected;

	//Send the data to PHP now
	varLoader.load(varSend);



}//close else condition for error handling

}

//function for validate email
function validate_email(s:String):Boolean 
{
var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var r:Object = p.exec(s);
if( r == null ) 
{
	return false;
}
return true;
}

//--------------Set tab index
userName.tabIndex = 1;
userEmail.tabIndex = 2;
userPhone.tabIndex = 3;
userCompany.tabIndex = 4;
userAddress.tabIndex=5;
userCity.tabIndex=6;
userState.tabIndex=7;
userZip.tabIndex=8;
userVehicle.tabIndex=9;
userFuel.tabIndex=10;

 

here's the php:

 

<?php

// Create local variables from the Flash ActionScript posted variables
$userName = $_POST['userName'];
$userEmail = $_POST['userEmail'];
$userPhone = $_POST['userPhone'];
$userCompany = $_POST['userCompany'];
$userAddress = $_POST['userAddress'];
$userCity = $_POST['userCity'];
$userState = $_POST['userState'];
$userZip = $_POST['userZip'];
$userVehicle = $_POST['userVehicle'];
$userFuel = $_POST['userFuel'];
$userNews = $_POST['subjectNews'];
$userBrochure = $_POST['subjectBrochure'];
$userStation = $_POST['subjectStation'];
$userSelling = $_POST['subjectSelling'];
$userFleet = $_POST['subjectFleet'];
$userPress = $_POST['subjectPress'];
$userCorporate = $_POST['subjectCorporate'];
$userOther = $_POST['subjectOther'];
$userMessage = $_POST['userMessage'];

// Strip slashes on the Local typed-in variables for security and run any php based error check here
$userName = stripslashes($userName);
$userEmail = stripslashes($userEmail);
$userMessage = stripslashes($userMessage); 

// IMPORTANT - Change these lines to be appropriate for your needs - IMPORTANT !!!!!!!!!!!!!!!!!!
$to = "david@creativegreen.org";			 
$from = "$userEmail";
$subject = "DMC Green Form Feedback";
// Modify the Body of the message however you like
$message = "Results from the form:

Name: $userName  
Email: $userEmail 
Phone: $userPhone
Company: $userCompany
Address: $userAddress
City: $userCity
State: $userState
Zip: $userZip
Vehicle: $userVehicle
Fuel: $userFuel
Newsletter: $userNews
Brochure: $userBrochure 
Station in my area: $userStation
Selling DMC fuels: $userSelling
Info for my fleet: $userFleet
Press/Public Relations Inquiry: $userPress
Corporate Affairs/Regulatory Inquiry: $userCorporate
Other Requests: $userOther

Their Message is below: 

$userMessage";
// Build $headers Variable
$headers = "From: $from\r\n";
$headers .= "Content-type: text\r\n"; 
$to = "$to";
    // Send the email
    mail($to, $subject, $message, $headers);

// Assemble the message that goes back to Flash
// The flash ActionScript is looking for a return variable of "return_msg"
$my_msg = "Thanks $userName, all data has been sent.";
// Print the data back to flash who is patiently waiting for it in the onCompleteHandler
    print "return_msg=$my_msg"; 
// Exit script	
exit();
?>

 

thanks again everyone!

 

 

Okay as your not viewing the PHP, it makes it harder to debug..

 

So i'll highlight the problem for you,

Your AS code does this

variables.userBrochure = subjectBrochure.selected;

 

But PHP expects this

$userBrochure = $_POST['subjectBrochure'];

 

Note the variable expects subjectBrochure but your passing userBrochure

 

So to fix the problem you can simply update the PHP code to this

$userNews = $_POST['userNews'];
$userBrochure = $_POST['userBrochure'];
$userStation = $_POST['userStation'];
$userSelling = $_POST['userSelling'];
$userFleet = $_POST['userFleet'];
$userPress = $_POST['userPress'];
$userCorporate = $_POST['userCorporate'];
$userOther = $_POST['userOther'];

The value would be true or false,

because subjectBrochure.selected is a boolean, My AS is a little rusty (but your get the idea) but you have 2 options

 

1. in AS

if(subjectBrochure.selected){variables.userBrochure = "SendBrochure"}else{variables.userBrochure = "Don't SendBrochure"}

 

2. in PHP

$userBrochure = ($_POST['subjectBrochure'] == "false")?"Don't SendBrochure":"SendBrochure";

Note: as subjectBrochure becomes a string from Flash your need the quotes

I used the PHP code, and it works great. I just put a blank value in for:

 

$userBrochure = ($_POST['userBrochure'] == "false")?"[color=red] - [/color]":"Send me a Brochure";

 

i think this is going to work out nice, thanks so much for all your help! i'm having a lot of fun learning these two languages, and i'm sure i'll be back very very soon for more help.

 

thanks again!!

Actually i have one more question... how do i make the results bold in the email?

 

Name: $userName
Email: $userEmail
Phone: $userPhone
Company: $userCompany
Address: $userAddress
City: $userCity
State: $userState
Zip: $userZip
Vehicle: $userVehicle
Fuel: $userFuel

Inquery:

$userNews
$userBrochure
$userStation
$userSelling
$userFleet
$userPress
$userCorporate
$userOther

 

just the $user... parts not the "name:" part.

 

thanks again

Your need to send a HTML email, and use HTML tags

so

Name: $userName

becomes

<B>Name:</B> $userName

 

So change your email from plain to html,

change

$headers .= "Content-type: text\r\n"; 

to

$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

 

EDIT: ooops forgot the \r\n

Now added

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.