Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-05-2003, 07:38 AM   #1
SKEMONE
Member
 
Join Date: Oct 2002
Location: Amsterdam, the Netherlands
Posts: 70
Default CGI/flash form

Hi

I have this Perl script called subscribe.cgi. What it does is send a simple email to a certain adress containing al the fields in a flash or html page. Does works fine.

The only thing is, it goes to a new page when you click the send button. This is not what I want. I want it to stay on the same page ( thus in the flash-movie). The thing is ... I haven't got a clue how to do this.

This is the script:

#!/usr/bin/perl

print "Content-type:text/plain\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$mailprog = '/usr/bin/sendmail';

# change this to your own email address

$recipient = '[email protected]';

# this opens an output stream and pipes it directly to the sendmail
# program. If sendmail can't be found, abort nicely by calling the
# dienice subroutine (see below)

open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n");

# here we're printing out the header info for the mail message. You must
# specify who it's to, or it won't be delivered:

print MAIL "To: $recipient\n";

# Reply-to can be set to the email address of the sender, assuming you
# have actually defined a field in your form called 'email'.

print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";

# print out a subject line so you know it's from your form cgi.
# The two \n\n's end the header section of the message. anything
# you print after this point will be part of the body of the mail.

print MAIL "Subject: Subscribe form\n\n";

#just alittle description of the mail

print MAIL "Somebody has filled in the subscribe form on ";

# here you're just printing out all the variables and values, just like
# before in the previous script, only the output is to the mail message
# rather than the followup HTML page.

foreach $key (keys(%FORM)) {
print MAIL "$key = $FORM{$key}\n";
}

# when you finish writing to the mail message, be sure to close the
# input stream so it actually gets mailed.

close(MAIL);

# print "Content-type: text/plain\n\nstatus=ok";>

# now print something to the HTML page, usually thanking the person
# for filling out the form, and giving them a link back to your homepage

print <<EndHTML;
<h2>Thank You</h2>
Thank you for writing. Your mail has been delivered.<p>
Return to our <a href="index.html">home page</a>.
</body></html>
EndHTML

sub dienice {
($errmsg) = @_;
print "<h2>Error</h2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";
exit;
}



hope you can help!
tnx in advance

SKEM

Last edited by SKEMONE; 02-06-2003 at 01:14 PM.
SKEMONE is offline   Reply With Quote
Old 02-05-2003, 02:54 PM   #2
jimburton
no sleep til bedtime
 
jimburton's Avatar
 
Join Date: May 2001
Location: Brighton
Posts: 1,322
Default

you can call it using a loadvars object with the send() method, then it will happen silently...you don't really need to change the perl ata ll, althoug the feedback to the user is now not needed...make you form fields into properties of the loadvars object then send it - check the tute on this if not used it b4
jimburton is offline   Reply With Quote
Old 02-05-2003, 03:05 PM   #3
SKEMONE
Member
 
Join Date: Oct 2002
Location: Amsterdam, the Netherlands
Posts: 70
Default

tnx jim

I used the LoadVariables() method with "POST" and it worked fine!

Do you also know how to do it with html?

So the browser won't go to another html page but stay in the html page where the form was send?

ltrs

SKEM
SKEMONE is offline   Reply With Quote
Old 02-05-2003, 03:09 PM   #4
jimburton
no sleep til bedtime
 
jimburton's Avatar
 
Join Date: May 2001
Location: Brighton
Posts: 1,322
Default

It's not really possible with html - probably closest is to use javascript to launch a small pop up, submit the form to the popup then close it....
jimburton is offline   Reply With Quote
Old 02-05-2003, 03:13 PM   #5
SKEMONE
Member
 
Join Date: Oct 2002
Location: Amsterdam, the Netherlands
Posts: 70
Default

well ain't that a b#tch...

tnx again and ltrs

SKEM ONE
SKEMONE is offline   Reply With Quote
Old 02-05-2003, 04:01 PM   #6
freddycodes
Master of Nothing
 
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
Default

Actually it is possible to do with just html. You can do it by adding the following line to your perl script. Right after the shebang line
Code:
print "Status: 204 No Response\n\n";
So like this.

Code:
#!/usr/bin/perl
print "Status: 204 No Response\n\n";
This well tell the html page that submits the form that there is nothing to display even though it will send the email out, so the html page would just sit as if nothing happened even though something is happening. Its a pretty cool feature for submitting forms without leaving where you are.
freddycodes is offline   Reply With Quote
Old 02-06-2003, 07:14 AM   #7
SKEMONE
Member
 
Join Date: Oct 2002
Location: Amsterdam, the Netherlands
Posts: 70
Default

thanx!

Some people already told me it wasn't possible...

ltrs

SKEM
SKEMONE is offline   Reply With Quote
Old 02-06-2003, 10:38 AM   #8
jimburton
no sleep til bedtime
 
jimburton's Avatar
 
Join Date: May 2001
Location: Brighton
Posts: 1,322
Default

you live and learn that's potentially very useful...I am hoping it works with php and the header() function...? will try out...thx freddycodes!
jimburton is offline   Reply With Quote
Old 02-06-2003, 10:53 AM   #9
jimburton
no sleep til bedtime
 
jimburton's Avatar
 
Join Date: May 2001
Location: Brighton
Posts: 1,322
Default

yes it does:

<?
//do something with the form data, then.......
header("Status: 204 No Response\n\n");

?>
jimburton is offline   Reply With Quote
Old 02-06-2003, 10:54 AM   #10
SKEMONE
Member
 
Join Date: Oct 2002
Location: Amsterdam, the Netherlands
Posts: 70
Default

true
SKEMONE is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:50 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.