Advice on starting form based application

D

dbmeyers23

All (sorry so long),

I've been handed a large word document that has many fields (150+)
fields in it. Management would like this form to be web based, so
errors can be detected and hopefully fixed before the form is submitted
and data can be required before submission.

The flow of this form will be the following:

1) User fills out form, but only will be filling in a handful of the
150+ fields.
2) User submits form, and a supervisor will recieve an email. At this
point, all they want is a basic text document with the data formatted
nicely so the supervisor can make changes and save the document. The
document will then be sent to a third party via email. FYI...data is
not sensitive, so a .doc or .txt would suffice.

My question is:

Is there a quick way to only display form values via cgi that have data
in them? So after hitting submit, a text file would be created that
only contains the values that they filled in. For example, if they
only fill in 5 of the 150 form values, what's the best way to display
only the data they filled in. I know how to test this for individual
values...but it will be lengthy for the amount of fields.
Thanks much.
 
B

Brian Wakem

All (sorry so long),

I've been handed a large word document that has many fields (150+)
fields in it. Management would like this form to be web based, so
errors can be detected and hopefully fixed before the form is submitted
and data can be required before submission.

The flow of this form will be the following:

1) User fills out form, but only will be filling in a handful of the
150+ fields.
2) User submits form, and a supervisor will recieve an email. At this
point, all they want is a basic text document with the data formatted
nicely so the supervisor can make changes and save the document. The
document will then be sent to a third party via email. FYI...data is
not sensitive, so a .doc or .txt would suffice.

My question is:

Is there a quick way to only display form values via cgi that have data
in them? So after hitting submit, a text file would be created that
only contains the values that they filled in. For example, if they
only fill in 5 of the 150 form values, what's the best way to display
only the data they filled in. I know how to test this for individual
values...but it will be lengthy for the amount of fields.
Thanks much.


#!/usr/bin/perl

use strict;
use CGI;
my $query = new CGI;

foreach($query->param()) {
if ($query->param($_) {
# print to text file
}
}
 
B

Brian Wakem

Brian said:
#!/usr/bin/perl

use strict;
use CGI;
my $query = new CGI;

foreach($query->param()) {
if ($query->param($_) {
# print to text file
}
}


Spot the deliberate mistake!


#!/usr/bin/perl

use strict;
use CGI;
my $query = new CGI;

foreach($query->param()) {
if ($query->param($_)) {
# print to text file
}
}
 
X

xhoster

For example, if they
only fill in 5 of the 150 form values, what's the best way to display
only the data they filled in. I know how to test this for individual
values...but it will be lengthy for the amount of fields.

Take the way you would test it for individual values, and put in a loop.

Xho
 
D

dbmeyers23

actually, i don't see yer mistake;-)

Okay, I guess my other problem would be this.

If I'm printing these results to a file, is there a way to know where
the values came from?

$query = CGI::new();
print $query->header();
$clientname = $query->param("clientname");
$agency = $query->param("agency");
$homedate = $query->param("homedate");
$a1 = $query->param("a1");
$a2 = $query->param("a2");
and on, and on....

So let's say they fill in everything above, excpet "a2"...how could
easily print this to a flat file so it looks like this.
Agency: Paper co.
Home Date: 12-12-2005
etc....


So if
 
G

Gunnar Hjalmarsson

If I'm printing these results to a file, is there a way to know where
the values came from?

There are obviously many ways.
$query = CGI::new();
print $query->header();

Didn't you say that you wanted to print them to a file?
So let's say they fill in everything above, excpet "a2"...how could
easily print this to a flat file so it looks like this.
Agency: Paper co.
Home Date: 12-12-2005
etc....

Whereever you print the stuff, hardcoding a list of param/label pairs is
one way:

my @labels = (
[ clientname => 'Client Name' ],
[ agency => 'Agency' ],
[ homedate => 'Home Date' ],
[ a1 => 'A1' ],
[ a2 => 'A2' ],
);

for (@labels) {
if ( $query->param( $$_[0] ) ) {
print "$$_[1]: ", $query->param( $$_[0] ), "\n";
}
}
 
D

dbmeyers23

Thanks Gunnar, this seems to work well. One last question if you don't
mind. Below is a snippet of the code. This prints out the values
wonderfully to the browser. I'd also like to write the contents to a
file, then mail the contents out. I can get the "Client Name:" to show
up in the email, but the variable is not showing up. I tried many
variations, with no luck...does anyone have any clues on how to do
this?


print $query->header();
my @labels = (
[ clientname => 'Client Name' ],
[ ordernumber => 'Order Number' ],
)
open (INT_EMAIL, ">/usr/local/apache2/ads/xxx.txt") || die "Can't open
email\n";

print "Success! <br>";
print "You entered the following information:<br>";
print "<br>";
for (@labels) {

if ( $query->param( $$_[0] ) ) {

print "$$_[1]: ", $query->param( $$_[0] ), "<br>";
printf INT_EMAIL ("$$_[1]: ", $query->param( $$_[0] ),
"\r\n");

}
}
close (INT_EMAIL);

$Subject="New Ad request";

`cat /usr/local/apache2/ads/xxx.txt | /bin/mail -u "ads" -s "$Subject"
ads\@mail.com`;
 
G

Gunnar Hjalmarsson

I'd also like to write the contents to a file, then mail the contents
out. I can get the "Client Name:" to show up in the email, but the
variable is not showing up.

printf INT_EMAIL ("$$_[1]: ", $query->param( $$_[0] ), "\r\n");

That's because you are using the wrong function. You want print().
( printf() is for formating, and has nothing to do with whether you
print to a file. )

In addition to that, you probably don't want "\r\n", but just "\n". In
Perl, "\n" represents the newline for the current platform.
`cat /usr/local/apache2/ads/xxx.txt | /bin/mail -u "ads"
-s "$Subject" ads\@mail.com`;

As regards sending emails from Perl, you may want to study

perldoc -q "send mail"

Doing so will show you that there is no need to save the message body to
a file before mailing it out.
 

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

No members online now.

Forum statistics

Threads
474,166
Messages
2,570,901
Members
47,442
Latest member
KevinLocki

Latest Threads

Top