form script question

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
 
J

J. Gleixner

David said:
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.

Whatever that is...

$vdeck->send_email({ -to => $to,
-from => $to,
-cc => [split ',', $cc],
-bcc => [split ',', $bcc],
-subject => "Feedback: from $form_meta->[2]",
-message => $message
});
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?

-subject => $q->param('name_of_hidden_subject_field'),

If $to is supplied via the form, then anyone can easily set it and use
your site to send E-Mail to anyone.
 
D

David Pyles

David said:
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.

Whatever that is...

$vdeck->send_email({ -to => $to,
-from => $to,
-cc => [split ',', $cc],
-bcc => [split ',', $bcc],
-subject => "Feedback: from $form_meta->[2]",
-message => $message
});
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?

-subject => $q->param('name_of_hidden_subject_field'),

If $to is supplied via the form, then anyone can easily set it and use
your site to send E-Mail to anyone.
Thanks. Mumia W. suggested the same thing in a private email, but it
soesn't work. I just get a server error. I guess I'll leave it as is.
Dave Pyles
 
J

J. Gleixner

David said:
David said:
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.

Whatever that is...

$vdeck->send_email({ -to => $to,
-from => $to,
-cc => [split ',', $cc],
-bcc => [split ',', $bcc],
-subject => "Feedback: from $form_meta->[2]",
-message => $message
});
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?

-subject => $q->param('name_of_hidden_subject_field'),

If $to is supplied via the form, then anyone can easily set it and use
your site to send E-Mail to anyone.
Thanks. Mumia W. suggested the same thing in a private email, but it
soesn't work. I just get a server error. I guess I'll leave it as is.
Dave Pyles

You're not giving us enough information to help you. What's the error
and the code you're using that causes the error?

If the HTML contains...

<form ...>
<input type="hidden" name="bar" value="foo">
....other form elements...
<input type="submit">
</form>

And the CGI program to process it contained something like:

use CGI;
my $q = CGI->new();
my $hidden_value = $q->param( 'bar' );


Then $hidden_value will be 'foo'.

Possibly it's something to do with 'VDeck', so maybe it's covered in
the documentation for that product.
 
G

Gunnar Hjalmarsson

David said:
... it soesn't work. I just get a server error.

To see what the server complains about, you can either check the error
log of the web server, or put this line in the beginning of the script:

use CGI::Carp 'fatalsToBrowser';
 
D

David Pyles

David said:
David Pyles wrote:
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.

Whatever that is...


$vdeck->send_email({ -to => $to,
-from => $to,
-cc => [split ',', $cc],
-bcc => [split ',', $bcc],
-subject => "Feedback: from $form_meta->[2]",
-message => $message
});


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?

-subject => $q->param('name_of_hidden_subject_field'),

If $to is supplied via the form, then anyone can easily set it and
use your site to send E-Mail to anyone.
Thanks. Mumia W. suggested the same thing in a private email, but it
soesn't work. I just get a server error. I guess I'll leave it as is.
Dave Pyles

You're not giving us enough information to help you. What's the error
and the code you're using that causes the error?

If the HTML contains...

<form ...>
<input type="hidden" name="bar" value="foo">
...other form elements...
<input type="submit">
</form>

And the CGI program to process it contained something like:

use CGI;
my $q = CGI->new();
my $hidden_value = $q->param( 'bar' );


Then $hidden_value will be 'foo'.

Possibly it's something to do with 'VDeck', so maybe it's covered in
the documentation for that product.
Thanks for the help. The VDeck" documentation truly sucks.
Dave
 
D

Dr.Ruud

Dr.Ruud schreef:
David Pyles:
$homedir || $vdeck->fatal_error("Can't determine home directory");

That line seems to have to be moved up about 8 lines.
Correction:

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");


I now read it as that the error is postponed on a purpose, until $vdeck
defined.
(So maybe there should be a die() added for when the new() fails.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top