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...
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...