PDA

View Full Version : Help with Flash Form and CGI Script


Darylt
12-06-2005, 07:28 PM
Can anyone explain or point me towards tutorials that can help me build a contact form in flash, and then send the data using CGI/PEARL?

Thanks

Cota
12-06-2005, 07:34 PM
Attached is a zip file containing a tutorial and all source files for sending data, for email purposes, using ASP, PHP, and Perl..

Darylt
12-07-2005, 05:37 AM
Thanks!!! :)

Darylt
12-09-2005, 08:58 AM
As I said, I am new to this......

I cant seem to find anywhere in the Flash file to enter the location of the cgi file, and I am unable to find somewhere in the cgi file to enter the final email address......

Thanks

Daryl

Cota
12-09-2005, 01:11 PM
in the flash file...there is a variable called serverlang...you can either change that to serverlang = "cgi" or hardcode the loadvars.send to the path of the cgi file. With in the perl script itself, there is a variable called ToEmail...you can simply make that equal to an email address like so
$ToEmail = "name\@domain.com";

Darylt
12-09-2005, 05:17 PM
I changed the $ToEmail = "name\@domain.com"; to include my email address, and also changed the first part of the movie to cgi.

I put the .cgi file in to the main directory and the cgi-bin file (as the whole directory is cgi enabled)

however I now get a failed message each time I try to test the form.

Any ideas....?

Cota
12-09-2005, 07:15 PM
Did you change the variable in the flash file?

Darylt
12-09-2005, 07:39 PM
The only thing that I changed in the flash file was the first line

var serverLang:String = "cgi";

Cota
12-09-2005, 07:44 PM
Also, look on the line that says
email_lv.sendAndLoad("SendMail."+serverLang, email_lv, "POST");

"SendMail" to the path of your cgi bin.

kevcar
06-23-2006, 05:56 PM
Could you please show an example of the asp script, as new to this and need all the help I can get

Cota
06-23-2006, 11:03 PM
welcome to the forums kevcar, what exactly is it that you need? Could you explain alittle more.

Skarab
03-27-2008, 03:01 PM
Hi Cota- I'm trying this script and I'm having the same problem(s) as Darylt. I've changed the To email in the cgi, placed it and the subparse.lib in the cgi-bin, and in the AS changed the var serverLang:String to "cgi".

Down below I've also changed the email_lv to : email_lv.sendAndLoad("cgi-bin/SendMail.cgi"+serverLang, email_lv, "POST")

but I get an "email failed" message in the status field.

Tutes and online help for Flash and cgi are pretty scarce. I'm working for a client whose hosting package doesn't allow php, or I'd be using that.

If you could clarify this it would be a great help.

Cota
03-27-2008, 08:11 PM
Can I see the relevant AS code and the Perl script you're using?

Skarab
03-27-2008, 09:12 PM
Here's what I've been testing, using the code you posted earlier in the thread. I've deleted your opening comments and commented out the serverLang:String:

var email_lv:LoadVars = new LoadVars();

//this function is called when email_lv loads the server-side script.
email_lv.onLoad = function(success) {
//If the script was successfully loaded, this condition is run
if (success) {
/* Though the server-side script was loaded, it does not mean it was
executed successfully. This condition gets a response from the
server-side script and determines if it was truly successful. */
if (email_lv.server_mes == "ok") {
status_txt.text = "Email Sent";
/* You can add additional code here. This is only run
if everything went as planned. */
}
} else {
//email failed to send, but script did load. Likely a server issue.
status_txt.text = "Email Failed";
}
};

/*This is the onRelease function for "submit_btn" button. This is only run
if the button was pressed. */
submit_btn.onRelease = function() {
/* Here we are validating the data. This insures the email address contains
both the "@" and ".", If not, it stops the script and alerts the user. */
if (!email_txt.length || email_txt.indexOf("@") == -1 || email_txt.indexOf(".") == -1) {
status_txt.text = "Invalid Email.";

//This validates the subject line contains text
} else if (!subject_txt.length) {
status_txt.text = "Missing Subject";

//This validates the message body contains text
} else if (!message_txt.length) {
status_txt.text = "Missing Message";

//If everything is filled out correctly, this is run.
} else {
//Collects the data from the text boxes and gives it to email_lv
email_lv.email_txt = email_txt.text;
email_lv.subject_txt = subject_txt.text;
email_lv.message_txt = message_txt.text;

/* Finally, send the data to the server and get a response.
As mentioned above, serverlang holds the file extendion for
the server side language. You can hard code the complete file name. */
email_lv.sendAndLoad("cgi-bin/SendMail.cgi", email_lv, "POST");
}
};


And here's the .cgi script. I altered the opening line (to match the shebang on a script created by the isp) and the ToEmail line, and put the subparse.lib in the cgi-bin with the cgi script:

#!/usr/bin/perl -w

require "subparse.lib";
&Parse_Form;

$theMail = $formdata{'email_txt'};
$theSubject = $formdata{'subject_txt'};
$theMessage = $formdata{'message_txt'};



$ToEmail = "[email protected]";
$ToSubject = $theSubject;
$EmailBody = $theMessage;


open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;
print MAIL "To: $theMail \nFrom: $theMail\n";
print MAIL "Subject: $theSubject\n";
print MAIL "$theMessage\n";
close (MAIL);

print "Content-type: text/html\n\n";
Print "server_mes=ok";

sub ErrorMessage {
print "server_mes=Fail";
exit; }

I've tested your Flash form with the script created by the isp, and it works as far as getting the data sent in an email. But it doesn't allow me to create a thankyou/success screen, and if the submit button is pressed more than once, subsequent emails come in with a lot of html as well as the text from the thank you screen i created with the isp's wizard. I'd like to be able to edit and troubleshoot this myself, but the isp's script is extremely long and beyond me.

Thanks for your quick response and any help you can offer!

Cota
03-27-2008, 11:51 PM
change this, Print "server_mes=ok"; to Print "&server_mes=ok";, do the same for the fail message. Not sure if thats the problem, but its worth a shot.

Skarab
03-28-2008, 01:36 AM
thanks Cota. I tried that, and still get "Email failed" in the status text area.

Cota
03-28-2008, 03:28 AM
try, email_lv.server_mes to this.server_mes

Skarab
03-28-2008, 02:27 PM
Thanks Cota. I tried this two ways, with the new edit you suggested,then also tried it after changing back the earlier suggestion about adding the & to the server_mes lines, and I got "Email failed" both ways.

I don't know if this is relevant, but the website is hosted on a Windows server, so I can't change permissions. The isp suggested the other day that I change permissions on the cgi-bin to 755, but when I do it just resets itself to 000.

Skarab
03-28-2008, 02:35 PM
I also just tried moving the cgi script and the subparse lib out of cgi-bin to the top level, but that didn't help.

Cota
03-28-2008, 08:20 PM
That 755 is usually required. You cant use PHP, but what about ASP? Personally, Perl is getting out dated.

Skarab
03-28-2008, 09:09 PM
OK, I'm looking into ASP. I'm also going back to the script the isp created, since, other probs aside, it works. I think the problems I'm having with it can be fixed in the actionscript rather than trying to niggle the cgi script, which is just not gonna happen.

As to the permissions thing, I don't think that's the issue since the isp script does work, though I did go back and try to change permissions on your script instead of the cgi-bin. Of course that didn't work but I had to try!

acsfilms
04-17-2009, 11:01 AM
Hi I have been trying out your form. In the asp code where do you insert the email address for the form data to be emailed to? I can see it in the php code but not the asp code. Also does the asp file and flash file have to be in the same directory or can the asp file be in a separate folder ie: cgi-bin if fully addressed there in the flash file.

cheers
andy