PDA

View Full Version : Upload to server AND eMail


dniezby
01-17-2007, 01:07 AM
I've created a flash form that needs to accept user's information (obviously) but the user will need to upload a file to the server.

Here is the AS I have in there now. It has to be done in AS1 as the program I use only uses AS1.

Could someone look at my fileRef.upload and see if I've done it right...If not, how can I send the form variables AND the file ref.

//Hide submit button until file is attached.
submit._visible = false;

// Hide result containter fields
submission_type._visible = false;
myresult.text._visible = false;

// Hide Error Messages
_root.missingfields._visible = false;
_root.error01._visible = false;

// Set checkbox values.
coverage.setValue (false);
consideration.setValue(false);


// Specify allowable file types.
var allTypes = new Array();

var docTypes = new Object();
docTypes.description = "Allowed Script Formats(*.pdf, *.celtx)";
docTypes.extention = "*.pdf; *.celtx";

allTypes.push(docTypes);

// Set up listener object to allow file selection via browse.
var listener = new Object();
listener.onSelect = function(file){
filename.text = file.name;
submit._visible = true;
}

listener.onIOError = function(file) {
log.addItem("An IO Error occured");
}

listener.onSecurityError = function(file, errorString) {
log.addItem("SecurityError: " + file.name + " ErrorString: " + errorString, "Error");
}

listener.onCancel = function(file){
filename.text = "Selection Canceled";
}

listener.onOpen = function(file) {
filename.text("onOpen: " + file.name);
}
listener.onProgress = function(file){

}
listener.onHTTPError = function(file, httpError) {
log.addItem("HTTP Error :" + httpError);
}
listener.onComplete = function(file) {
//Event triggered when file is uploaded.
//log.addItem("File is uploaded");
//pauseFor(3000);
//gotoAndPlay(3);
}


// Set up file listener for file reference.
var fileRef = new flash.net.FileReference();
fileRef.addListener(listener);

// BROWSE BUTTON FUNCTIONS
browse.onClick = function(){
fileRef.browse([{description: "Allowed Script Formats", extension: "*.pdf;*.celtx"}]);
}


//SUBMIT BUTTON FUNCTIONS
submit.onClick = function(){
// CHECK FOR MISSING FIELDS
if (!first.text||!last.text||!h_addy.text||city.text| |state.text||!phone.text||!email_addy.text||!stitl e.text||!synopsis.text||!submission_type){
// MISSING FIELDS. PLAY ERROR MESSAGE
_root.missingfields._visible = true;
_root.missingfields.gotoAndPlay("go");
submit._visible = false;
filename.text = "";
}else{
// Set up LoadVariables
var lv_result = new LoadVars ();
lv_result.onLoad = function (success){
//Clear form fields
first.text="";
last.text ="";
h_addy.text = "";
city.text = "";
state.text = "";
zip.text = "";
phone.text = "";
email_addy.text = "";
stitle.text = "";
synopsis.text = "";
wga.text = "";
usc.text = "";
submission_type.text ="";
filename.text = "";
consideration.setValue (false);
coverage.setValue (false);
submit._visible = false;
myresponse.text = lv_result.myresult;

}

fileRef.upload("uploaddb.php");

}
var send_lv = new LoadVars();
send_lv.fname = fname.text;
send_lv.lname = lname.text;
send_lv.h_addy = h_addy.text;
send_lv.city = city.text;
send_lv.state = state.text;
send_lv.zip = zip.text;
send_lv.phone = phone.text;
send_lv.email_addy = email_addy.text;
send_lv.stitle = stitle.text;
send_lv.synopsis = synopsis.text;
send_lv.wga = wga.text;
send_lv.usc = usc.text;
send_lv.submission_type = submission_type.text;
send_lv.filename = filename.text;
send_lv.sendAndLoad("uploaddb.php",lv_result,"POST");
};

// CLEAR BUTTON FUNCTION
clr.onClick = function(){
first.text="";
last.text ="";
h_addy.text = "";
city.text = "";
state.text = "";
zip.text = "";
phone.text = "";
email_addy.text = "";
stitle.text = "";
synopsis.text = "";
wga.text = "";
usc.text = "";
submission_type.text = "";
filename.text = "";
consideration.setValue (false);
coverage.setValue (false);
}


The php file uploaddb.php has the code to process the form fields and upload the move_uploaded_file statement...I just need to find a way to get the file to the server AND use that data to create an email...(I know how to create the email though...

lelales
01-17-2007, 02:12 PM
I think the only thing you can do with Flash is send the data in name variable pairs to the PHP script. Then from PHP, you can write to a database or a file, process the info and email it to whoever.

Here's some PHP code:<?
// start the session
session_start()header("Cache-control: private"); //IE 6 Fi

// Get the user's input from the form
$custname = $_POST['custname'];
// Register the input with the value
$_SESSION['custname'] = $custname;

// Get the user's input from the form
$custcompany = $_POST['custcompany'];
// Register the input with the value
$_SESSION['custcompany'] = $custcompany;

//set up mail variables
$to = "you@yourdomain.com," . $_SESSION['custemail']; #set address to send form to
$subject = "Metapps Online Order Form form"; #set the subject line
$headers = "From: Metro Appraisal Services"; #set the from address

## set up the time ##
$date = date ("l, F jS, Y");
$time = date ("h:i A");
## mail the message ##
$msg = "Thank you for choosing Metro Appraisal Services
This is a confirmation of your online appraisal request.
It was submitted on $date at $time.\n

Requested by:
Customer name = " . $_SESSION['custname'] . "
Customer Company= " . $_SESSION['custcompany'];
mail($to, $subject, $msg, $headers);
?>

dniezby
01-17-2007, 06:42 PM
Looking at the code, I realized that there was a different procedure to do what I wanted.
So, here is what I did. I set the form to hide the actual email SUBMIT button until a file had been uploaded. Then it appears.

listener.onComplete = function(file){
// File's been uploaded, show the form submit button.
_root.uploadsuccess._visible = true;
_root.uploadsuccess.gotoAndPlay("go");
submit._visible = true;
}