You want to limit a user's ability to submit a form.
That's not usually part of any standard formmail script.
To do that, you'll need to identify the user:
You can attempt to do that by:
a) E-mail address
b) IP address
c) Cookies
However, the only way to dependably identify a user is by cookies, and even that won't be 100% dependable.
Suggestions:
1) Search for: big nose bird survey
2) Get the free script that attempts to do what you want.
3) Rip out the cookies code and add it to your formmail script.
#!/usr/bin/perl
######################################################
# The following cookie driver will check for the expiration of a cookie.
# If the cookie does not exist or has expired it will perform the code
# in the Cookie_Accepted subroutine and if the cookie has not yet
# expired it will perform the code in the Cookie_Rejected subroutine.
######################################################
######################################################
# Set $Seconds to the number of seconds until the cookie expires.
# Set $Seconds to 0 to remove the cookie.
#
# 1 minute = 1 * 60 = 60 seconds
# 1 hour = 1 * 60 * 60 = 3600 seconds
# 1 day = 1 * 60 * 60 * 24 = 86400 seconds
# 1 week = 1 * 60 * 60 * 24 * 7 = 604800 seconds
# 1 month = 1 * 60 * 60 * 24 * 30 = 2592000 seconds
# 1 year = 1 * 60 * 60 * 24 * 352 = 30412800 seconds
######################################################
$Seconds = 30;
######################################################
# Set $Cookie_Name to a unique name to identify this cookie.
######################################################
$Cookie_Name = "$ENV{SCRIPT_NAME}"; # unix script pathname
######################################################
# Pre-processing.
######################################################
# Insert any optional & additional initialization here.
# Initialize variables, parse forms, perform calculations, etc.
######################################################
# Check cookie.
######################################################
&Check_Cookie;
######################################################
# Post-processing.
######################################################
# Insert any optional & additional finalization here.
# Send emails, delete temporary files, spawn process, etc.
######################################################
# Done.
######################################################
exit;
######################################################
# Get, check, set, or remove cookie and display current status.
######################################################
sub Check_Cookie {
if ( $Seconds eq 0 ) {
$cookie=&Remove_Cookie( $Cookie_Name );
print "$cookie\n";
&Cookie_Status('REMOVED', "Expires in $Seconds seconds");
} else {
$Cookie_Value = &Get_Cookie( $Cookie_Name );
if ( $Cookie_Value > time ) {
&Cookie_Rejected;
} else {
$cookie = &Set_Cookie( $Cookie_Name, time + $Seconds, $Seconds );
print "$cookie\n";
&Cookie_Accepted;
}
}
}
######################################################
# Takes (name,value,hours) as arguments to set a cookie.
# 0 hours means a current browser session cookie life.
######################################################
sub Set_Cookie {
my ( $name, $value, $expires ) = @_;
$name = &Cookie_Scrub( $name );
$value = &Cookie_Scrub( $value );
# $expires=$expires * 60;
# $expires=int($expires);
my $expire_at = &Cookie_Date( $expires );
my $namevalue = "$name=$value";
my $COOKIE = "";
if ( $expires!= 0 ) {
$COOKIE = "Set-Cookie: $namevalue; expires=$expire_at; ";
}
else {
$COOKIE = "Set-Cookie: $namevalue; "; #current session cookie if 0
}
return $COOKIE;
}
######################################################
# This routine removes cookie of (name) by setting the expiration to a
# date/time GMT of (now - 24hours)
######################################################
sub Remove_Cookie {
my ( $name ) = @_;
$name = &Cookie_Scrub( $name );
my $value = "";
my $cookie = "";
my $expires = &Cookie_Date( -86400 );
my $namevalue = "$name=$value";
my $COOKIE = "Set-Cookie: $namevalue; expires=$expires; ";
return $COOKIE;
}
######################################################
# given a cookie name, this routine returns the value component of the
# name=value pair. A returned value of 0 means no cookie.
######################################################
sub Get_Cookie {
my ( $name ) = @_;
$name = &Cookie_Scrub( $name );
my $temp = $ENV{'HTTP_COOKIE'};
@pairs = split(/\; /,$temp);
foreach my $sets ( @pairs ) {
my ( $key, $value ) = split( /=/, $sets );
$clist{$key} = $value;
}
if ( $clist{$name} eq "" ) { $clist{$name}="0"; }
my $retval = $clist{$name};
return $retval;
}
######################################################
# Number of seconds added to the server time to calculate expiration.
# Cookie time is ALWAYS GMT.
######################################################
sub Cookie_Date {
my ( $seconds ) = @_;
my %mn = ( 'Jan','01', 'Feb','02', 'Mar','03', 'Apr','04', 'May','05', 'Jun','06', 'Jul','07', 'Aug','08', 'Sep','09', 'Oct','10', 'Nov','11', 'Dec','12' );
my $sydate = gmtime( time+$seconds );
my ( $day, $month, $num, $time, $year ) = split( /\s+/, $sydate );
my $zl = length( $num );
if ( $zl == 1 ) {
$num = "0$num";
}
my $retdate = "$day $num-$month-$year $time GMT";
return $retdate;
}
######################################################
# Don't allow = or ; as valid elements of name or data
######################################################
sub Cookie_Scrub {
my ( $retval ) = @_;
$retval=~s/\;//g;
$retval=~s/\=//g;
return $retval;
}
######################################################
# Display Cookie Status Message
######################################################
sub Cookie_Status {
my ( $action, $detail ) = @_;
print "Content-type: text/html\n\n";
print <<__END_MESSAGE__;
<H2 ALIGN=Center>$Cookie_Name COOKIE $action</H2>
<H3 ALIGN=Center>$detail</H3>
__END_MESSAGE__
}
######################################################
# Stop. Cookie has not yet expired.
######################################################
sub Cookie_Rejected {
&Cookie_Status('REJECTED', ( $Cookie_Value - time ) . " of $Seconds seconds remaining");
}
######################################################
# OK to continue processing.
######################################################
sub Cookie_Accepted {
&Cookie_Status('ACCEPTED', "Expires in $Seconds seconds");
}
Then just merge the basics of your formmail script into it.
There's very little left to make it do what you want but if you're not comfortable with writing your own scripts or modifying existing ones this will probably be over your head.
What's left:
1) Parse the form (Pre-Processing).
2) Send the results by email (Cookie_Accepted).