D
David Pyles
I'm a web designer, but not a perl programmer. I've been working on
some forms using the form mail program that is part of VDeck. The
default set-up sends an email with a default Subject line. Since I will
have a number of forms, I would like to customize the Subject line to
reflect the form that generated the email by entering a hidden subject
field in the form with a value that would be entered in the subject line
of the email. My web host does not provide help in modifying their
scripts. The told me to modify the forms.cgi, but they wouldn't tell me
how. I tried modifying the the script, but my mods just give me server
errors. I'm hoping to get some help here.
Here is the forms.cgi unmodified script:
#!/usr/bin/perl
############################################
#
# forms.cgi - form processor for forms created though admin panel
#
# (c) 2003 vDeck.com
#
############################################
use strict;
use warnings;
use CGI;
use vDeckPublic;
use DBI;
use constant F_ID => 0;
use constant F_FORMID => 1;
use constant F_FIELDNAME => 2;
use constant F_FIELD_TYPE => 3;
use constant F_FIELD_DEFAULT => 4;
use constant F_FIELD_TAINTCHECK => 5; # for future use
use constant F_FIELD_RANK => 6;
my $q = CGI->new();
# find homedir
my $homedir = '';
$ENV{DOCUMENT_ROOT} =~ m|(/home/[\w\-]+)| and $homedir = $1;
# print "Content-type: text/plain\n\n--$homedir--"; exit(0);
my $vdeck = vDeckPublic->new({ -db =>
"DBI:CSV:f_dir=$homedir/.panel/data/;csv_eol=\n;",
-user => '',
-pass => '' });
$homedir || $vdeck->fatal_error("Can't determine home directory");
my $form_id='';
my %var = $q->Vars();
foreach my $f_name(keys %var){
if($f_name =~ /^_(\w+)formid$/){
$q->param($f_name) =~ /(\d+)/ and $form_id = $1;
last;
}
}
$form_id || $vdeck->fatal_error("Invalid form ID. Please check your SSI
code!");
# WHERE form_id='$form_id'
my $form_fields = $vdeck->db_query("SELECT * FROM form_fields WHERE
form_id='$form_id'");
defined $form_fields->[0] or $vdeck->fatal_error("No form fields defined
- please check your form design.");
my %form_field = ();
for (@{$form_fields}) {
my $field_name = $_->[2];
$field_name =~ s/\W/_/g;
defined ( $q->param($field_name) ) and $form_field{$field_name} =
$q->param($field_name);
}
# everything OK, so send e-mail
my $form_meta = $vdeck->db_query("SELECT * FROM form_meta WHERE
id='$form_id'",'rowarray');
defined $form_meta->[0] or $vdeck->ssi_error("Invalid form ID. Please
check your SSI code!");
my $to = $form_meta->[3];
my $cc = $form_meta->[4];
my $bcc = $form_meta->[5];
my $message = $form_meta->[6];
my $redirect = $form_meta->[7] || '/v-web/forms/thanks.htm';
while ($message =~ /\[% (\S+) %\]/s) {
my $attr = $1;
$message =~ s/\[% $attr %\]/$form_field{$attr}/gs;
}
$vdeck->send_email({ -to => $to,
-from => $to,
-cc => [split ',', $cc],
-bcc => [split ',', $bcc],
-subject => "Feedback: from $form_meta->[2]",
-message => $message
});
print $q->redirect($redirect);
exit(0);
Can someone tell me how to modify this script to make it pick-up the
value of a hidden "subject" field in the form and place it's value in
the subject line of the resulting email?
Thanks in advance.
Dave Pyles
some forms using the form mail program that is part of VDeck. The
default set-up sends an email with a default Subject line. Since I will
have a number of forms, I would like to customize the Subject line to
reflect the form that generated the email by entering a hidden subject
field in the form with a value that would be entered in the subject line
of the email. My web host does not provide help in modifying their
scripts. The told me to modify the forms.cgi, but they wouldn't tell me
how. I tried modifying the the script, but my mods just give me server
errors. I'm hoping to get some help here.
Here is the forms.cgi unmodified script:
#!/usr/bin/perl
############################################
#
# forms.cgi - form processor for forms created though admin panel
#
# (c) 2003 vDeck.com
#
############################################
use strict;
use warnings;
use CGI;
use vDeckPublic;
use DBI;
use constant F_ID => 0;
use constant F_FORMID => 1;
use constant F_FIELDNAME => 2;
use constant F_FIELD_TYPE => 3;
use constant F_FIELD_DEFAULT => 4;
use constant F_FIELD_TAINTCHECK => 5; # for future use
use constant F_FIELD_RANK => 6;
my $q = CGI->new();
# find homedir
my $homedir = '';
$ENV{DOCUMENT_ROOT} =~ m|(/home/[\w\-]+)| and $homedir = $1;
# print "Content-type: text/plain\n\n--$homedir--"; exit(0);
my $vdeck = vDeckPublic->new({ -db =>
"DBI:CSV:f_dir=$homedir/.panel/data/;csv_eol=\n;",
-user => '',
-pass => '' });
$homedir || $vdeck->fatal_error("Can't determine home directory");
my $form_id='';
my %var = $q->Vars();
foreach my $f_name(keys %var){
if($f_name =~ /^_(\w+)formid$/){
$q->param($f_name) =~ /(\d+)/ and $form_id = $1;
last;
}
}
$form_id || $vdeck->fatal_error("Invalid form ID. Please check your SSI
code!");
# WHERE form_id='$form_id'
my $form_fields = $vdeck->db_query("SELECT * FROM form_fields WHERE
form_id='$form_id'");
defined $form_fields->[0] or $vdeck->fatal_error("No form fields defined
- please check your form design.");
my %form_field = ();
for (@{$form_fields}) {
my $field_name = $_->[2];
$field_name =~ s/\W/_/g;
defined ( $q->param($field_name) ) and $form_field{$field_name} =
$q->param($field_name);
}
# everything OK, so send e-mail
my $form_meta = $vdeck->db_query("SELECT * FROM form_meta WHERE
id='$form_id'",'rowarray');
defined $form_meta->[0] or $vdeck->ssi_error("Invalid form ID. Please
check your SSI code!");
my $to = $form_meta->[3];
my $cc = $form_meta->[4];
my $bcc = $form_meta->[5];
my $message = $form_meta->[6];
my $redirect = $form_meta->[7] || '/v-web/forms/thanks.htm';
while ($message =~ /\[% (\S+) %\]/s) {
my $attr = $1;
$message =~ s/\[% $attr %\]/$form_field{$attr}/gs;
}
$vdeck->send_email({ -to => $to,
-from => $to,
-cc => [split ',', $cc],
-bcc => [split ',', $bcc],
-subject => "Feedback: from $form_meta->[2]",
-message => $message
});
print $q->redirect($redirect);
exit(0);
Can someone tell me how to modify this script to make it pick-up the
value of a hidden "subject" field in the form and place it's value in
the subject line of the resulting email?
Thanks in advance.
Dave Pyles