Gossamer Forum
Home : Products : DBMan : Customization :

Field update via email form

Quote Reply
Field update via email form
Hello all,

I have searched long and hard for an answer to this one but can't seem to find exactly what is needed - let me try to explain:

1. I would like to automatically update a field called 'history' when I send an email via a form that is generated by an addition to the standard DBMan - 'sub html_sixmth_email_form' (see below). When the submit button is clicked 'sub sixth_email' is then run (see further below)

2. The automatic update text for field 'history'is based on a hidden field in the form called 'new comment' plus a date and time stamp, so I'm trying to use something like:

# if ($in{'newcomment'}) {
#
# my ($datestamp,$timestamp,$datetime);
#
# $datestamp = &get_date;
# $timestamp = &get_time;
# $datetime = "$datestamp $timestamp";
# $in{'history'} .= "\n$datetime $in{'newcomment'}"; # append history field
# }

My problem to date is probably fairly basic for any Perl expert but being a relative newbie I can't see where I'm going wrong - The email is sent OK, the history field and the ID field are carried through the process OK, but the rest of the fields are all blank - it would seem that I haven't transferred the information in the rest of the fields successfully?

Any help or pointers would be appreciated


Keef


# SIX MONTH MESSAGE ADDITION - This sub routine added for Six Month Message
sub html_sixmth_email_form {
#----------------------------------------------------------
my ($message) = $_[0];
$in{$db_key} =~ s/<?.B>//g;
%rec = &get_record($in{$db_key});

$page_title = "Email Six Month Message";
&html_page_top;

if ($message) { print qq|<FONT SIZE="-2" FACE="arial, helvetica" COLOR="#FF0000">There was a problem: $message</FONT><BR>|; }
print qq|
<FONT SIZE="-2" FACE="arial, helvetica">Fill in any extra message
that you would like to add - the standard 'six month message' will
be attached to the end of your message.</FONT>
|;

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<input type=hidden name="$db_key" value="$in{$db_key}">
<input type=hidden name="newcomment" value="Six month message">|;

print qq|
<table><tr><td align=right><FONT SIZE="-2" FACE="arial, helvetica" COLOR="#FF6600">Your message:</font></td>
<td><textarea name="emailmessage" cols=50 rows=10 wrap="virtual">$in{'emailmessage'}</TEXTAREA></td></tr>
</table>
<center>
<INPUT TYPE="SUBMIT" NAME="sixmth_email" VALUE="Send Email">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center>
</form>
|;

&html_footer;
&html_page_bottom;
}


# SIX MONTH MESSAGE ADDITION - This subroutine added for the Six Month Message
sub sixmth_email {
# --------------------------------------------------------
#
unless ($admin_email) { $message = "Admin email has not been entered in the .cfg file<BR>"; }
unless ($admin_email =~ /.+\@.+\..+/) { $message = "Admin email address is not in the correct format.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }

%rec = &get_record($in{$db_key});

if ($in{'newcomment'}) {

my ($datestamp,$timestamp,$datetime);

$datestamp = &get_date;
$timestamp = &get_time;
$datetime = "$datestamp $timestamp";
$in{'history'} .= "\n$datetime $in{'newcomment'}"; # append history field
}

if ($message) {
chomp($message);
&html_sixmth_email_form($message);
return;
}

# message text
$end_message = qq|
Message goes here
|;

my $smtp = Net::SMTP->new('post.isp.co.uk',
Hello => 'www.domain.com',
Timeout => 30,
Debug => 0
);
die "Couldn't connect to server" unless $smtp;

$smtp->mail("webmaster\@domain.com");
$smtp->to("$rec{$db_email_field}");
$smtp->bcc("$admin_email");
$smtp->data();
$smtp->datasend("To: $rec{$db_email_field}\n");
$smtp->datasend("From: $admin_email\n");
$smtp->datasend("Sender: $admin_email\n");
$smtp->datasend("Subject: Subject of email\n\n");
$smtp->datasend("-" x 75 . "\n");
$smtp->datasend("$in{'emailmessage'}\n");
$smtp->datasend("$end_message\n");
$smtp->dataend();

$smtp->quit;

&html_sixmth_email_success;
}