form script question

form script question

am 29.07.2007 14:51:50 von Dave 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

Re: form script question

am 30.07.2007 18:47:36 von glex_no-spam

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.

Re: form script question

am 30.07.2007 20:42:11 von Dave Pyles

On 7/30/2007 12:47 PM, J. Gleixner wrote:
> 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

Re: form script question

am 30.07.2007 22:10:30 von glex_no-spam

David Pyles wrote:
> On 7/30/2007 12:47 PM, J. Gleixner wrote:
>> 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...



....other form elements...



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.

Re: form script question

am 30.07.2007 22:22:34 von Gunnar Hjalmarsson

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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: form script question

am 30.07.2007 23:11:57 von Dave Pyles

On 7/30/2007 4:10 PM, J. Gleixner wrote:
> David Pyles wrote:
>> On 7/30/2007 12:47 PM, J. Gleixner wrote:
>>> 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...
>
>


>
> ...other form elements...
>
>

>
> 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

Re: form script question

am 11.08.2007 16:54:47 von rvtol+news

David Pyles schreef:

> $homedir || $vdeck->fatal_error("Can't determine home directory");

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

--
Affijn, Ruud

"Gewoon is een tijger."

Re: form script question

am 11.08.2007 17:34:01 von rvtol+news

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.)

--
Affijn, Ruud

"Gewoon is een tijger."

Re: form script question

am 16.09.2007 08:00:13 von mnwebguy

create a hidden field in your form named "Subject" and give it a value,
then in forms.cgi - in the section
$vdeck->send_email({ -to => $to,
-from => $to,
-cc => [split ',', $cc],
-bcc => [split ',', $bcc],
-subject => "Feedback: from $form_meta->[2]",
-message => $message
});

replace:
-subject => "Feedback: from $form_meta->[2]",
with:
-subject => $form_field{Subject},

and it will do what you want, just be aware that the field name is case
sensitive and must match the form spelling including case

--
Message posted using http://www.talkaboutprogramming.com/group/comp.lang.perl.mis c/
More information at http://www.talkaboutprogramming.com/faq.html