PDA

View Full Version : formmail.pl and ActionScript


kypsul
11-20-2005, 08:29 AM
I am working with a flash web site and ActionScript 2.0. I am having a major issue with trying to turn off the "redirect" variable in the CGI script.

I handle all of the responses and redirects in the actionscript, however when a user sends an email, my actionscript runs and then the CGI script pops up a new browser window with the default HTML response. This a useful feature in HTML websites but a real pain in Flash sites.

Does anyone know how to ignore the "redirect" variable in the cgi script, or does anyone know how to tell the redirect in actionscript to stay on the root and not open up the new response page?

FishMonger
11-20-2005, 11:20 AM
Have you tried to comment out the redirect line?

kypsul
11-20-2005, 04:37 PM
yeah,

the script then pops up a new browser window and gives me an Error Code 500.

FishMonger
11-20-2005, 04:59 PM
Can you post the cgi script? Without knowing what it's doing and how, it will be impossible for us to tell you how to stop it from popping up a new window.

kypsul
11-20-2005, 06:11 PM
the link is www.aerolitestudios.com/duckyou/site/index.html

You will need to download the latest flash player, v 8.0

Once you are into the site, click on the contacts page and fill in the required fields.

You will get the pop up message.

Thank for the help...

Kyle

kypsul
11-20-2005, 06:34 PM
This is the actionscript code

//------------------------<send form LoadVars>------------------------\\
var gatherForm:LoadVars = new LoadVars();

function sendForm(){
gatherForm.recipient = "ksullivan@aerolitestudios.com";
gatherForm.comments = emailForm.usrMessage.text;
gatherForm.realname = emailForm.usrName.text;
gatherForm.subject = emailForm.usrSubject.text;

gatherForm.send("/cgi-bin/formmail.pl", "POST");
}
//------------------------</send form LoadVars>------------------------\\


The only thing that I can do with the "redirect" varable is tell it what page to go to but it will not accept a frame within the flash player.

In other words the code would have to be something like:

gatherForm.redirect = "http://domain.com/redirect.html"

This would allow me to control what HTML page the form redirects the user to. This is great if I were working in HTML, however, I am working with flash and the actionscript already handles the redirect.

FishMonger
11-20-2005, 07:14 PM
I don't do any work with flash, so I can't help in that area.

If the redirection is comming from the cgi script, then we'll need to look at its code to see what needs to be done to disable the redirect.

FishMonger
11-20-2005, 07:23 PM
If you're using the FormMail script from Matt's Script Archive, you should replace it with the nms FormMail script. The nms version is much better.

The nms Project
http://nms-cgi.sourceforge.net/scripts.shtml

Here's Matt's reasons why you should use the nms script instead of his own.
http://www.scriptarchive.com/nms.html

kypsul
11-20-2005, 07:45 PM
The cgi "redirect" code is as follows

# Return HTML Page or Redirect User
&return_html;


sub return_html {
# Local variables used in this subroutine initialized. #
local($key,$sort_order,$sorted_field);

# Now that we have finished using form values for any e-mail related #
# reasons, we will convert all of the form fields and config values #
# to remove any cross-site scripting security holes. #
local($field);
foreach $field (keys %Config) {
$safeConfig{$field} = &clean_html($Config{$field});
}

foreach $field (keys %Form) {
$Form{$field} = &clean_html($Form{$field});
}


# If redirect option is used, print the redirectional location header. #
if ($Config{'redirect'}) {
print "Location: $safeConfig{'redirect'}\n\n";
}

# Otherwise, begin printing the response page. #
else {

# Print HTTP header and opening HTML tags. #
print "Content-type: text/html\n\n";
print "<html>\n <head>\n";

# Print out title of page #
if ($Config{'title'}) { print "<title>$safeConfig{'title'}</title>\n" }
else { print "<title>Thank You</title>\n" }

print " </head>\n <body";

# Get Body Tag Attributes #
&body_attributes;

# Close Body Tag #
print ">\n <center>\n";

# Print custom or generic title. #
if ($Config{'title'}) { print "<h1>$safeConfig{'title'}</h1>\n" }
else { print "<h1>Thank You For Filling Out This Form</h1>\n" }

print "</center>\n";

print "Below is what you submitted to $safeConfig{'recipient'} on ";
print "$date<p><hr size=1 width=75\%><p>\n";

# If a sort order is specified, sort the form fields based on that. #
if ($Config{'sort'} =~ /^order:.*,.*/) {

# Set the temporary $sort_order variable to the sorting order, #
# remove extraneous line breaks and spaces, remove the order: #
# directive and split the sort fields into an array. #
$sort_order = $Config{'sort'};
$sort_order =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$sort_order =~ s/(\s+)?\n+(\s+)?//g;
$sort_order =~ s/order://;
@sorted_fields = split(/,/, $sort_order);

# For each sorted field, if it has a value or the print blank #
# fields option is turned on print the form field and value. #
foreach $sorted_field (@sorted_fields) {
local $sfname = &clean_html($sorted_field);

if ($Config{'print_blank_fields'} || $Form{$sorted_field} ne '') {
print "<b>$sfname:</b> $Form{$sorted_field}<p>\n";
}
}
}

# Otherwise, use the order the fields were sent, or alphabetic. #
else {

# Sort alphabetically if requested.
if ($Config{'sort'} eq 'alphabetic') {
@Field_Order = sort @Field_Order;
}

# For each form field, if it has a value or the print blank #
# fields option is turned on print the form field and value. #
foreach $field (@Field_Order) {
local $fname = &clean_html($field);

if ($Config{'print_blank_fields'} || $Form{$field} ne '') {
print "<b>$fname:</b> $Form{$field}<p>\n";
}
}
}

print "<p><hr size=1 width=75%><p>\n";

# Check for a Return Link and print one if found. #
if ($Config{'return_link_url'} && $Config{'return_link_title'}) {
print "<ul>\n";
print "<li><a href=\"$safeConfig{'return_link_url'}\">$safeConfig{'return_link_title'}</a>\n";
print "</ul>\n";
}

# Print the page footer. #
print <<"(END HTML FOOTER)";
<hr size=1 width=75%><p>
<center><font size=-1><a href="http://www.scriptarchive.com/formmail.html">FormMail</a> V1.92 &copy; 1995 - 2002 Matt Wright<br>
A Free Product of <a href="http://www.scriptarchive.com/">Matt's Script Archive, Inc.</a></font></center>
</body>
</html>
(END HTML FOOTER)
}
}

I have commented the &return_html; out by placing the # in front but I just get an error code 500 by doing that. Any suggestions?

FishMonger
11-20-2005, 08:29 PM
Have you checked the web server error log? It should give some additional info on what's causing the 500 error.

kypsul
11-20-2005, 08:38 PM
When I comment the return_html out I get this error

Premature end of script headers: formmail.pl

FishMonger
11-20-2005, 09:11 PM
Are you trying to 'turn off the "redirect" variable' or not have the cgi script return anything at all?

If you want to prevent the redirection, comment out this section of the subroutine.
# If redirect option is used, print the redirectional location header. #
if ($Config{'redirect'}) {
print "Location: $safeConfig{'redirect'}\n\n";
}

That error message is telling you that the FormMail script did not return a complete set of html headers. If you don't want the FormMail script to return any html, then your flash scripts will need to do it. Since I don't work with flash, I can't say how that is done.